-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution3232.go
More file actions
61 lines (47 loc) · 1.12 KB
/
solution3232.go
File metadata and controls
61 lines (47 loc) · 1.12 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package solution3232
// ============================================================================
// 3232. Find if Digit Game Can Be Won
// URL: https://leetcode.com/problems/find-if-digit-game-can-be-won/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/3232---Find-if-Digit-Game-Can-Be-Won
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_canAliceWingV2
Benchmark_canAliceWingV2-24 1000000000 2.556 ns/op 0 B/op 0 allocs/op
Benchmark_canAliceWingV1
Benchmark_canAliceWingV1-24 279003758 4.297 ns/op 0 B/op 0 allocs/op
PASS
*/
func canAliceWinV2(nums []int) bool {
var as, ad int
for _, v := range nums {
switch {
case v >= 1 && v <= 9:
as += v
default:
ad += v
}
}
return as-ad != 0
}
func canAliceWinV1(nums []int) bool {
var as, ad, bs, bd int
for _, v := range nums {
if v >= 1 && v <= 9 {
as += v
} else {
bd += v
}
if v >= 10 && v <= 99 {
ad += v
} else {
bs += v
}
}
if as > bd || ad > bs {
return true
}
return false
}