Skip to content

Commit 4c5412a

Browse files
aQuaaQua
authored andcommitted
822 added
1 parent 198b291 commit 4c5412a

File tree

4 files changed

+83
-4
lines changed

4 files changed

+83
-4
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# [822. Card Flipping Game](https://leetcode.com/problems/card-flipping-game/)
2+
3+
## 题目
4+
5+
On a table are N cards, with a positive integer printed on the front and back of each card (possibly different).
6+
7+
We flip any number of cards, and after we choose onecard.
8+
9+
If the number X on the back of the chosencard is not on the front of any card, then this number X is good.
10+
11+
What is the smallest number that is good? If no number is good, output 0.
12+
13+
Here, fronts[i] and backs[i] represent the number on the front and back of card i.
14+
15+
Aflip swaps the front and back numbers, so the value on the front is now on the back and vice versa.
16+
17+
Example:
18+
19+
Input: fronts = [1,2,4,4,7], backs = [1,3,4,1,3]
20+
Output: 2
21+
Explanation: If we flip the second card, the fronts are [1,3,4,4,7] and the backs are [1,2,4,1,3].
22+
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.
23+
24+
Note:
25+
26+
1. 1 <= fronts.length == backs.length<=1000.
27+
1. 1 <=fronts[i]<= 2000.
28+
1. 1 <= backs[i]<= 2000.
29+
30+
## 解题思路
31+
32+
见程序注释
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem0822
2+
3+
func flipgame(fronts []int, backs []int) int {
4+
5+
return 0
6+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package problem0822
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
// tcs is testcase slice
11+
var tcs = []struct {
12+
fronts []int
13+
backs []int
14+
ans int
15+
}{
16+
17+
{
18+
[]int{1, 2, 4, 4, 7},
19+
[]int{1, 3, 4, 1, 3},
20+
2,
21+
},
22+
23+
// 可以有多个 testcase
24+
}
25+
26+
func Test_flipgame(t *testing.T) {
27+
ast := assert.New(t)
28+
29+
for _, tc := range tcs {
30+
fmt.Printf("~~%v~~\n", tc)
31+
ast.Equal(tc.ans, flipgame(tc.fronts, tc.backs), "输入:%v", tc)
32+
}
33+
}
34+
35+
func Benchmark_flipgame(b *testing.B) {
36+
for i := 0; i < b.N; i++ {
37+
for _, tc := range tcs {
38+
flipgame(tc.fronts, tc.backs)
39+
}
40+
}
41+
}

leetcode.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
33
"Ranking": 1098,
4-
"Updated": "2018-05-18T05:13:06.382625511+08:00",
4+
"Updated": "2018-05-18T08:23:56.463665066+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 168,
@@ -613,7 +613,7 @@
613613
"ID": 49,
614614
"Title": "Group Anagrams",
615615
"TitleSlug": "group-anagrams",
616-
"PassRate": "38%",
616+
"PassRate": "39%",
617617
"Difficulty": "Medium",
618618
"IsAccepted": true,
619619
"IsPaid": false,
@@ -2089,7 +2089,7 @@
20892089
"ID": 172,
20902090
"Title": "Factorial Trailing Zeroes",
20912091
"TitleSlug": "factorial-trailing-zeroes",
2092-
"PassRate": "36%",
2092+
"PassRate": "37%",
20932093
"Difficulty": "Easy",
20942094
"IsAccepted": true,
20952095
"IsPaid": false,
@@ -3073,7 +3073,7 @@
30733073
"ID": 254,
30743074
"Title": "Factor Combinations",
30753075
"TitleSlug": "factor-combinations",
3076-
"PassRate": "43%",
3076+
"PassRate": "44%",
30773077
"Difficulty": "Medium",
30783078
"IsAccepted": false,
30793079
"IsPaid": true,

0 commit comments

Comments
 (0)