|
1 | 1 | [#0822-card-flipping-game] |
2 | | -= 822. Card Flipping Game |
| 2 | += 822. 翻转卡片游戏 |
3 | 3 |
|
4 | | -{leetcode}/problems/card-flipping-game/[LeetCode - Card Flipping Game^] |
| 4 | +https://leetcode.cn/problems/card-flipping-game/[LeetCode - 822. 翻转卡片游戏^] |
5 | 5 |
|
6 | | -On a table are `N` cards, with a positive integer printed on the front and back of each card (possibly different). |
| 6 | +在桌子上有 `n` 张卡片,每张卡片的正面和背面都写着一个正数(正面与背面上的数有可能不一样)。 |
7 | 7 |
|
8 | | -We flip any number of cards, and after we choose one card. |
| 8 | +我们可以先翻转任意张卡片,然后选择其中一张卡片。 |
9 | 9 |
|
10 | | -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. |
| 10 | +如果选中的那张卡片背面的数字 `x` 与任意一张卡片的正面的数字都不同,那么这个数字是我们想要的数字。 |
11 | 11 |
|
12 | | -What is the smallest number that is good? If no number is good, output `0`. |
| 12 | +哪个数是这些想要的数字中最小的数(找到这些数中的最小值)呢?如果没有一个数字符合要求的,输出 `0`。 |
13 | 13 |
|
14 | | -Here, `fronts[i]` and `backs[i]` represent the number on the front and back of card `i`. |
| 14 | +其中, `fronts[i]` 和 `backs[i]` 分别代表第 `i` 张卡片的正面和背面的数字。 |
15 | 15 |
|
16 | | -A flip swaps the front and back numbers, so the value on the front is now on the back and vice versa. |
| 16 | +如果我们通过翻转卡片来交换正面与背面上的数,那么当初在正面的数就变成背面的数,背面的数就变成正面的数。 |
17 | 17 |
|
18 | | -*Example:* |
| 18 | +*示例 1:* |
19 | 19 |
|
20 | | -[subs="verbatim,quotes,macros"] |
21 | | ----- |
22 | | -*Input:* fronts = [1,2,4,4,7], backs = [1,3,4,1,3] |
23 | | -*Output:* `2` |
24 | | -*Explanation:* If we flip the second card, the fronts are `[1,3,4,4,7]` and the backs are `[1,2,4,1,3]`. |
25 | | -We choose the second card, which has number 2 on the back, and it isn't on the front of any card, so `2` is good. |
26 | | ----- |
| 20 | +.... |
| 21 | +输入:fronts = [1,2,4,4,7], backs = [1,3,4,1,3] |
| 22 | +输出:2 |
| 23 | +解释:假设我们翻转第二张卡片,那么在正面的数变成了 [1,3,4,4,7] , 背面的数变成了 [1,2,4,1,3]。 |
| 24 | +接着我们选择第二张卡片,因为现在该卡片的背面的数是 2,2 与任意卡片上正面的数都不同,所以 2 就是我们想要的数字。 |
| 25 | +.... |
| 26 | + |
| 27 | +*示例 2:* |
27 | 28 |
|
28 | | - |
| 29 | +.... |
| 30 | +输入:fronts = [1], backs = [1] |
| 31 | +输出:0 |
| 32 | +解释: |
| 33 | +无论如何翻转都无法得到想要的数字,所以返回 0 。 |
| 34 | +.... |
29 | 35 |
|
30 | | -*Note:* |
| 36 | +*提示:* |
31 | 37 |
|
| 38 | +* `n == fronts.length == backs.length` |
| 39 | +* `1 \<= n \<= 1000` |
| 40 | +* `1 \<= fronts[i], backs[i] \<= 2000` |
32 | 41 |
|
33 | | -. `1 <= fronts.length == backs.length <= 1000`. |
34 | | -. `1 <= fronts[i] <= 2000`. |
35 | | -. `1 <= backs[i] <= 2000`. |
36 | 42 |
|
37 | 43 |
|
| 44 | +== 思路分析 |
38 | 45 |
|
| 46 | +首先,排除的是正反面一样的数字。剩下的数字里,找最小的数字即可。有点想复杂了。 |
39 | 47 |
|
40 | 48 | [[src-0822]] |
| 49 | +[tabs] |
| 50 | +==== |
| 51 | +一刷:: |
| 52 | ++ |
| 53 | +-- |
41 | 54 | [{java_src_attr}] |
42 | 55 | ---- |
43 | 56 | include::{sourcedir}/_0822_CardFlippingGame.java[tag=answer] |
44 | 57 | ---- |
| 58 | +-- |
| 59 | +
|
| 60 | +// 二刷:: |
| 61 | +// + |
| 62 | +// -- |
| 63 | +// [{java_src_attr}] |
| 64 | +// ---- |
| 65 | +// include::{sourcedir}/_0822_CardFlippingGame_2.java[tag=answer] |
| 66 | +// ---- |
| 67 | +// -- |
| 68 | +==== |
| 69 | + |
| 70 | + |
| 71 | +== 参考资料 |
45 | 72 |
|
| 73 | +. https://leetcode.cn/problems/card-flipping-game/solutions/2368863/yue-du-li-jie-ti-pythonjavacgojs-by-endl-ze7f/[822. 翻转卡片游戏 - 阅读理解题^] |
| 74 | +. https://leetcode.cn/problems/card-flipping-game/solutions/2365854/fan-zhuan-qia-pian-you-xi-by-leetcode-so-acbj/[822. 翻转卡片游戏 - 官方题解^] |
0 commit comments