Skip to content

Commit 4dfa618

Browse files
committed
Time: 2 ms (85.53%), Space: 39.7 MB (81.58%) - LeetHub
1 parent c979a5b commit 4dfa618

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
fun pivotIndex(nums: IntArray): Int {
3+
var total = 0
4+
var leftTotal = 0
5+
nums.forEach{
6+
total += it
7+
}
8+
9+
nums.forEachIndexed { index, num ->
10+
if(total - leftTotal - num == leftTotal) return index
11+
leftTotal += num
12+
}
13+
14+
return -1
15+
}
16+
}

0 commit comments

Comments
 (0)