Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2042 from alexprudhomme/0724-find-pivo…
Browse files Browse the repository at this point in the history
…t-index.cs

Create: 0724-find-pivot-index.cs
  • Loading branch information
tahsintunan authored Jan 16, 2023
2 parents 464dd75 + 08aabe9 commit 3737a86
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions csharp/0724-find-pivot-index.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Solution {
public int PivotIndex(int[] nums) {
int total = nums.Sum();

int leftSum = 0;

for (int i = 0; i < nums.Length; i++)
{
if (leftSum == total - leftSum - nums[i])
{
return i;
}

leftSum += nums[i];
}
return -1;
}
}

0 comments on commit 3737a86

Please sign in to comment.