Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Elizabeth/DigitGame/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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
44 changes: 44 additions & 0 deletions Elizabeth/DigitGame/digit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Solution(object):
def canAliceWin(self, nums):
"""
:type nums: List[int]
:rtype: bool
Elizabeth
Truphena
Risper
"""
#initialize the variables to an empty list
single_digit_nums=[]
double_digit_nums=[]
#condition to add the single digits and double digits to their respective lists
for i in nums:
if 0<=i<=9:
single_digit_nums.append(i)#adds each element between 0 and 9

for i in nums:
if 10<=i<=99:
double_digit_nums.append(i)#adds each element between 10 and 99
#sum of the single and double digits
sum_single_digits=sum(single_digit_nums)
sum_double_digits=sum(double_digit_nums)
#scenario 1 if Alice receives sum of single digits
Alice_single=sum_single_digits
Bob_double=sum_double_digits
#scenario 2 if Alice receives sum of double digits
Alice_double=sum_double_digits
Bob_single=sum_single_digits
#condition if Alice receives more than Bob
if(Alice_single>Bob_double) or (Alice_double>Bob_single):
return True
else:
return False

print(canAliceWin.__doc__)

solution=Solution()
#nums = [1,2,3,4,10]
#nums = [1,2,3,4,5,14]
nums = [5,5,5,25]
print(solution.canAliceWin(nums))