• [LintCode] Nuts & Bolts Problem 螺栓螺母问题


    Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping between nuts and bolts. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to see which one is bigger/smaller.

    We will give you a compare function to compare nut with bolt.
    Have you met this question in a real interview?
    Example

    Given nuts = ['ab','bc','dd','gg'], bolts = ['AB','GG', 'DD', 'BC'].

    Your code should find the matching bolts and nuts.

    one of the possible return:

    nuts = ['ab','bc','dd','gg'], bolts = ['AB','BC','DD','GG'].

    we will tell you the match compare function. If we give you another compare function.

    the possible return is the following:

    nuts = ['ab','bc','dd','gg'], bolts = ['BC','AA','DD','GG'].

    So you must use the compare function that we give to do the sorting.

    The order of the nuts or bolts does not matter. You just need to find the matching bolt for each nut.

  • 相关阅读:
    js数组
    js字符串和控制语句
    生成器、列表解析
    js属性
    js函数
    js变量
    python抽象方法
    python 装饰器的缺点以及解决方法
    windows文件关联、打开方式列表之修改注册表攻略
    JavaScript定时器及其他
  • 原文地址:https://www.cnblogs.com/grandyang/p/5833107.html
Copyright © 2020-2023  润新知