cs: add “724. Find Pivot Index”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2024-01-07 16:00:47 +01:00
parent 8171cd6289
commit 7fb942c159
Signed by: mfocko
GPG key ID: 7C47D46246790496

18
cs/find-pivot-index.cs Normal file
View file

@ -0,0 +1,18 @@
public class Solution {
public int PivotIndex(int[] nums) {
var fromLeft = 0;
var fromRight = nums.Sum();
for (var i = 0; i < nums.Length; ++i) {
fromRight -= nums[i];
if (fromLeft == fromRight) {
return i;
}
fromLeft += nums[i];
}
return -1;
}
}