-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
traverse the vector, time: O(N)
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |