Skip to content

Commit

Permalink
Create 2270. Number of Ways to Split Array
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Jan 3, 2025
1 parent 59078ab commit d927338
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions 2270. Number of Ways to Split Array
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public:
int waysToSplitArray(vector<int>& nums)
{
vector<long> pref;
pref.push_back(0);
for(auto val : nums) pref.push_back(pref.back() + val);

int ans = 0, n = nums.size();
for(int i = 1; i < n; i++)
if(pref[i] >= pref.back() - pref[i]) ans++;
return ans;
}
};

0 comments on commit d927338

Please sign in to comment.