Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f56fa7b

Browse files
author
Sandy
authored
Merge pull request #226 from openset/develop
Update: Find Pivot Index
2 parents ade4588 + 2b913c1 commit f56fa7b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

‎problems/find-pivot-index/find_pivot_index.go

Lines changed: 2 additions & 4 deletions
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

Lines changed: 4 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /