We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3a92bff commit 71acff7Copy full SHA for 71acff7
Arrays/724_Find_Pivot_Index.java
@@ -1,21 +1,18 @@
1
class Solution {
2
public int pivotIndex(int[] nums) {
3
- if (nums == null || nums.length == 0) {
4
- return -1;
5
- }
6
-
7
int currSum = 0, totalSum = 0;
8
9
for (int n : nums) {
10
totalSum += n;
11
}
12
13
for (int i = 0; i < nums.length; i++) {
14
- if (currSum + nums[i] == totalSum) {
+ currSum += nums[i];
+
+ if (totalSum == currSum) {
15
return i;
16
17
18
- currSum += nums[i];
19
totalSum -= nums[i];
20
21
0 commit comments