mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
18 lines
363 B
C#
18 lines
363 B
C#
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;
|
|
}
|
|
}
|