[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 ,如需转载请自行联系原博主。

相关文章
|
Oracle 关系型数据库 数据库
Oracle中merge Into的用法
Oracle中merge Into的用法
|
Java fastjson API
Springboot 整合 xxljob 动态API调度任务(进阶篇)
Springboot 整合 xxljob 动态API调度任务(进阶篇)
8203 0
Springboot 整合 xxljob 动态API调度任务(进阶篇)
|
Java 分布式数据库 数据库
软件各种系统架构图
原文:软件各种系统架构图 https://blog.csdn.net/everythingss/article/details/78749247     该技术架构图是本人根据多年企业技术架构经验而制定,是企业技术的总架构图,希望对CTO们有所借鉴。
8718 0
|
开发工具 git 开发者
|
机器学习/深度学习 数据处理
【机器学习】生成式模型与判别式模型有什么区别?
【5月更文挑战第10天】【机器学习】生成式模型与判别式模型有什么区别?
|
机器学习/深度学习 资源调度 自然语言处理
长短时记忆网络(LSTM)完整实战:从理论到PyTorch实战演示
长短时记忆网络(LSTM)完整实战:从理论到PyTorch实战演示
19300 0
【多线程面试题二十五】、说说你对AQS的理解
这篇文章阐述了对Java中的AbstractQueuedSynchronizer(AQS)的理解,AQS是一个用于构建锁和其他同步组件的框架,它通过维护同步状态和FIFO等待队列,以及线程的阻塞与唤醒机制,来实现同步器的高效管理,并且可以通过实现特定的方法来自定义同步组件的行为。
【多线程面试题二十五】、说说你对AQS的理解
|
JavaScript 前端开发 开发者
Vue学习之--------深入理解Vuex、原理详解、实战应用(2022/9/1)
这篇文章详细介绍了Vuex的基本概念、使用场景、安装配置、基本用法、实际应用案例以及注意事项,通过一个数字累加器的实战示例,帮助开发者深入理解Vuex的原理和应用。
|
存储 关系型数据库 算法框架/工具
Ceph对象网关,多区域网关
Ceph对象网关,多区域网关
193 6
|
存储 Kubernetes Docker
深入探索容器化技术:Docker 实战与 Kubernetes 管理
深入探索容器化技术:Docker 实战与 Kubernetes 管理
381 0