Skip to content

Commit 270ff26

Browse files
committed
更新 problem 1005
1 parent 8038b02 commit 270ff26

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Algorithms/1005. Maximize Sum Of Array After K Negations/1005. Maximize Sum Of Array After K Negations.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package leetcode
22

3-
import "sort"
3+
import (
4+
"sort"
5+
)
46

57
func largestSumAfterKNegations(A []int, K int) int {
68
sort.Ints(A)
79
minIdx := 0
810
for i := 0; i < K; i++ {
911
A[minIdx] = -A[minIdx]
10-
if minIdx == len(A)-1 || A[minIdx+1] < A[minIdx] {
12+
if A[minIdx+1] < A[minIdx] {
1113
minIdx++
1214
}
1315
}

0 commit comments

Comments
 (0)