8000 Create 724. Find Pivot Index · yashnayan8795/Leetcode-Challenge@6e9885c · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e9885c

Browse files
authored
Create 724. Find Pivot Index
1 parent fa01af5 commit 6e9885c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

724. Find Pivot Index

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

0 commit comments

Comments
 (0)
0