forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1275.go
More file actions
35 lines (33 loc) · 721 Bytes
/
Copy path1275.go
File metadata and controls
35 lines (33 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
func tictactoe(moves [][]int) string {
score := make([][]int, 2)
for i := 0; i < 2; i++ {
score[i] = make([]int, 8)
}
p := 0
for _, it := range moves {
score[p][it[0]]++
score[p][it[1] + 3]++
score[p][6] += btoi(it[0] == it[1])
score[p][7] += btoi(it[0] + it[1] == 2)
for _, x := range score[p] {
if x == 3 {
if p == 0 {
return "A"
} else {
return "B"
}
}
}
p ^= 1
}
if len(moves) == 9 {
return "Draw"
}
return "Pending"
}
func btoi(b bool) int {
if b {
return 1
}
return 0
}