We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bc75371 commit 2b913c1Copy full SHA for 2b913c1
problems/find-pivot-index/find_pivot_index.go
@@ -6,12 +6,10 @@ func pivotIndex(nums []int) int {
6
right += v
7
}
8
for i, v := range nums {
9
- right -= v
10
- if left == right {
+ if right -= v; left == right {
11
return i
12
- } else {
13
- left += v
14
+ left += v
15
16
return -1
17
problems/find-pivot-index/find_pivot_index_test.go
@@ -29,6 +29,10 @@ func TestPivotIndex(t *testing.T) {
29
input: []int{1, 2, 1},
30
expected: 1,
31
},
32
+ {
33
+ input: []int{},
34
+ expected: -1,
35
+ },
36
37
for _, tc := range tests {
38
output := pivotIndex(tc.input)
0 commit comments