-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3232-FindIfDigitGameCanBeWon.go
More file actions
68 lines (58 loc) · 1.91 KB
/
3232-FindIfDigitGameCanBeWon.go
File metadata and controls
68 lines (58 loc) · 1.91 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
62
63
64
65
66
67
68
package main
// 3232. Find if Digit Game Can Be Won
// You are given an array of positive integers nums.
// Alice and Bob are playing a game.
// In the game, Alice can choose either all single-digit numbers or all double-digit numbers from nums, and the rest of the numbers are given to Bob.
// Alice wins if the sum of her numbers is strictly greater than the sum of Bob's numbers.
// Return true if Alice can win this game, otherwise, return false.
// Example 1:
// Input: nums = [1,2,3,4,10]
// Output: false
// Explanation:
// Alice cannot win by choosing either single-digit or double-digit numbers.
// Example 2:
// Input: nums = [1,2,3,4,5,14]
// Output: true
// Explanation:
// Alice can win by choosing single-digit numbers which have a sum equal to 15.
// Example 3:
// Input: nums = [5,5,5,25]
// Output: true
// Explanation:
// Alice can win by choosing double-digit numbers which have a sum equal to 25.
// Constraints:
// 1 <= nums.length <= 100
// 1 <= nums[i] <= 99
import "fmt"
func canAliceWin(nums []int) bool {
one, two := 0, 0
for _, v := range nums {
if v >= 10 {
two += v
} else {
one += v
}
}
if one == two { return false }
return true
}
func main() {
// Example 1:
// Input: nums = [1,2,3,4,10]
// Output: false
// Explanation:
// Alice cannot win by choosing either single-digit or double-digit numbers.
fmt.Println(canAliceWin([]int{1,2,3,4,10})) // false
// Example 2:
// Input: nums = [1,2,3,4,5,14]
// Output: true
// Explanation:
// Alice can win by choosing single-digit numbers which have a sum equal to 15.
fmt.Println(canAliceWin([]int{1,2,3,4,5,14})) // true
// Example 3:
// Input: nums = [5,5,5,25]
// Output: true
// Explanation:
// Alice can win by choosing double-digit numbers which have a sum equal to 25.
fmt.Println(canAliceWin([]int{5,5,5,25})) // true
}