From ac6687cee15913061a0d03f60ba5f8993f6b0b33 Mon Sep 17 00:00:00 2001 From: aucker Date: Sat, 30 Nov 2024 22:28:58 +0800 Subject: [PATCH] Nov30: can alice win [E] traverse the vector, time: O(N) --- daily/Nov30.cc | 17 +++++++++++++++++ daily/Nov30.rs | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 daily/Nov30.cc create mode 100644 daily/Nov30.rs diff --git a/daily/Nov30.cc b/daily/Nov30.cc new file mode 100644 index 0000000..b2790c1 --- /dev/null +++ b/daily/Nov30.cc @@ -0,0 +1,17 @@ +#include +using namespace std; + +class Solution { + public: + bool canAlignWin(vector& 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; + } +}; diff --git a/daily/Nov30.rs b/daily/Nov30.rs new file mode 100644 index 0000000..1541d32 --- /dev/null +++ b/daily/Nov30.rs @@ -0,0 +1,16 @@ +impl Solution { + pub fn can_alice_win(nums: Vec) -> 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 + } +}