mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-04 16:12:47 +08:00
更新 problem 1005
This commit is contained in:
@ -1,13 +1,15 @@
|
||||
package leetcode
|
||||
|
||||
import "sort"
|
||||
import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
func largestSumAfterKNegations(A []int, K int) int {
|
||||
sort.Ints(A)
|
||||
minIdx := 0
|
||||
for i := 0; i < K; i++ {
|
||||
A[minIdx] = -A[minIdx]
|
||||
if minIdx == len(A)-1 || A[minIdx+1] < A[minIdx] {
|
||||
if A[minIdx+1] < A[minIdx] {
|
||||
minIdx++
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user