Skip to content

Commit

Permalink
Nov30: can alice win [E]
Browse files Browse the repository at this point in the history
traverse the vector, time: O(N)
  • Loading branch information
aucker committed Nov 30, 2024
1 parent c5b107c commit ac6687c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions daily/Nov30.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>
using namespace std;

class Solution {
public:
bool canAlignWin(vector<int>& nums) {
int oneSum = 0, twoSum = 0;
for (int num : nums) {
if (num > 0 && num < 10) {
oneSum += num;
} else {
twoSum += num;
}
}
return (oneSum == twoSum) ? false : true;
}
};
16 changes: 16 additions & 0 deletions daily/Nov30.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
impl Solution {
pub fn can_alice_win(nums: Vec<i32>) -> bool {
let (mut oneSum, mut twoSum) = (0, 0);
for num in &nums {
if *num > 0 && *num < 10 {
oneSum += *num;
} else {
twoSum += *num;
}
}
if oneSum != twoSum {
return true;
}
false
}
}

0 comments on commit ac6687c

Please sign in to comment.