Skip to content

Commit 5c3ce42

Browse files
authored
Create 2270. Number of Ways to Split Array (#680)
2 parents 59078ab + d927338 commit 5c3ce42

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

2270. Number of Ways to Split Array

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
int waysToSplitArray(vector<int>& nums)
4+
{
5+
vector<long> pref;
6+
pref.push_back(0);
7+
for(auto val : nums) pref.push_back(pref.back() + val);
8+
9+
int ans = 0, n = nums.size();
10+
for(int i = 1; i < n; i++)
11+
if(pref[i] >= pref.back() - pref[i]) ans++;
12+
return ans;
13+
}
14+
};

0 commit comments

Comments
 (0)