Skip to content

Commit 71acff7

Browse files
committed
Update 724_Find_Pivot_Index.java
1 parent 3a92bff commit 71acff7

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Arrays/724_Find_Pivot_Index.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
class Solution {
22
public int pivotIndex(int[] nums) {
3-
if (nums == null || nums.length == 0) {
4-
return -1;
5-
}
6-
73
int currSum = 0, totalSum = 0;
84

95
for (int n : nums) {
106
totalSum += n;
117
}
128

139
for (int i = 0; i < nums.length; i++) {
14-
if (currSum + nums[i] == totalSum) {
10+
currSum += nums[i];
11+
12+
if (totalSum == currSum) {
1513
return i;
1614
}
1715

18-
currSum += nums[i];
1916
totalSum -= nums[i];
2017
}
2118

0 commit comments

Comments
 (0)