Skip to content

Commit 08aabe9

Browse files
committed
Create: 0724-find-pivot-index.cs
1 parent fa2d4c3 commit 08aabe9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

csharp/0724-find-pivot-index.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Solution {
2+
public int PivotIndex(int[] nums) {
3+
int total = nums.Sum();
4+
5+
int leftSum = 0;
6+
7+
for (int i = 0; i < nums.Length; i++)
8+
{
9+
if (leftSum == total - leftSum - nums[i])
10+
{
11+
return i;
12+
}
13+
14+
leftSum += nums[i];
15+
}
16+
return -1;
17+
}
18+
}

0 commit comments

Comments
 (0)