[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.

本文转自博客园Grandyang的博客,原文链接:螺栓螺母问题[LintCode] Nuts & Bolts Problem ,如需转载请自行联系原博主。

相关文章
UVa1531 - Problem Bee
UVa1531 - Problem Bee
51 0
|
Unix Python
LeetCode 71. Simplify Path
给定文件的绝对路径(Unix下的路径)字符串,简化此字符串。
84 0
LeetCode 71. Simplify Path
|
物联网 Go C++
洛谷【2】P1001 A+B Problem
洛谷【2】P1001 A+B Problem
|
数据挖掘
HDOJ 1032(POJ 1207) The 3n + 1 problem
HDOJ 1032(POJ 1207) The 3n + 1 problem
129 0
【leetcode】Contest98
一开始本来打算省时间用特么的有道翻译, 结果直接懵逼了。其实还是自己看题目, 结合例子理解一下很快的。   1. 题1(3分) 题目 888. Fair Candy Swap Difficulty: Easy Alice and Bob have candy bars of d...
1215 0
|
机器学习/深度学习 自然语言处理