diff --git a/waysToSplitArray.cpp b/waysToSplitArray.cpp new file mode 100644 index 0000000..a088f7e --- /dev/null +++ b/waysToSplitArray.cpp @@ -0,0 +1,33 @@ +#include +#include +using namespace std; + +class Solution { +public: + int waysToSplitArray(vector& nums) { + long long sum1 = 0; + int lens = nums.size(); + for(int i = 0; i < lens;i++){ + sum1 += nums[i]; + } + long long sum2 = 0; + int counter = 0; + lens--; + for(int i = 0; i < lens;i++){ + sum2 += nums[i]; + sum1 -= nums[i]; + if(sum2 >= sum1){ + counter++; + } + } + + return counter; + } +}; + +int main(){ + vector nums = {10,4,-8,7}; + Solution solution; + cout << solution.waysToSplitArray(nums) << endl; + return 0; +} \ No newline at end of file