mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-24 02:14:00 +08:00
规范格式
This commit is contained in:
@ -0,0 +1,29 @@
|
||||
package leetcode
|
||||
|
||||
func longestOnes(A []int, K int) int {
|
||||
res, left, right := 0, 0, 0
|
||||
for left < len(A) {
|
||||
if right < len(A) && ((A[right] == 0 && K > 0) || A[right] == 1) {
|
||||
if A[right] == 0 {
|
||||
K--
|
||||
}
|
||||
right++
|
||||
} else {
|
||||
if K == 0 || (right == len(A) && K > 0) {
|
||||
res = max(res, right-left)
|
||||
}
|
||||
if A[left] == 0 {
|
||||
K++
|
||||
}
|
||||
left++
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func max(a int, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
Reference in New Issue
Block a user