Skip to content

Commit 45e971c

Browse files
authored
724. Find Pivot Index
1 parent 9f439a3 commit 45e971c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

724.FindPivotIndex.kt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//https://leetcode.com/problems/find-pivot-index/description
2+
class Solution {
3+
fun pivotIndex(nums: IntArray): Int {
4+
val sum = nums.sum()
5+
var leftSum = 0
6+
7+
for(i in nums.indices){
8+
if(leftSum == sum -leftSum - nums[i]){
9+
return i
10+
}
11+
leftSum += nums[i]
12+
}
13+
return -1
14+
}
15+
}

0 commit comments

Comments
 (0)