822. Card Flipping Game
题目描述
On a table are N cards, with a positive integer printed on the front and back of each card (possibly different).
We flip any number of cards, and after we choose one card.
If the number X on the back of the chosen card is not on the front of any card, then this number X is good.
What is the smallest number that is good? If no number is good, output 0.
Here, fronts[i] and backs[i] represent the number on the front and back of card i.
A flip swaps the front and back numbers, so the value on the front is now on the back and vice versa.
Example:
|
|
Note:
- 1 <= fronts.length == backs.length <= 1000.
- 1 <= fronts[i] <= 2000.
- 1 <= backs[i] <= 2000.
题目大意
每张牌的正反面都有一个数,随意翻牌,找出一个最小的数与其他牌当前的正面数值不相等。front
代表牌正面的数值,back
代表牌背面的数值。
解题思路
如果正反面数值相同,则无论我们如何翻这张牌,正面的牌一定不符合条件。
找出正反面数值相同。将数值存在集合内。
遍历front
和back
,找到不在集合中存在的最小数。
代码
|
|