Skip to content

Commit 2b913c1

Browse files
committed
Update: Find Pivot Index
1 parent bc75371 commit 2b913c1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

problems/find-pivot-index/find_pivot_index.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ func pivotIndex(nums []int) int {
66
right += v
77
}
88
for i, v := range nums {
9-
right -= v
10-
if left == right {
9+
if right -= v; left == right {
1110
return i
12-
} else {
13-
left += v
1411
}
12+
left += v
1513
}
1614
return -1
1715
}

problems/find-pivot-index/find_pivot_index_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ func TestPivotIndex(t *testing.T) {
2929
input: []int{1, 2, 1},
3030
expected: 1,
3131
},
32+
{
33+
input: []int{},
34+
expected: -1,
35+
},
3236
}
3337
for _, tc := range tests {
3438
output := pivotIndex(tc.input)

0 commit comments

Comments
 (0)