cs: add «2270. Number of Ways to Split Array»
URL: https://leetcode.com/problems/number-of-ways-to-split-array/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
7e297a3605
commit
3a4809d6f8
1 changed files with 17 additions and 0 deletions
17
cs/number-of-ways-to-split-array.cs
Normal file
17
cs/number-of-ways-to-split-array.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
public class Solution {
|
||||
public int WaysToSplitArray(int[] nums) {
|
||||
var (leftSum, rightSum) = (0l, nums.Select(x => (long)x).Sum());
|
||||
|
||||
var count = 0;
|
||||
for (var i = 0; i < nums.Length - 1; ++i) {
|
||||
leftSum += nums[i];
|
||||
rightSum -= nums[i];
|
||||
|
||||
if (leftSum >= rightSum) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue