add new solutions
This commit is contained in:
parent
886b5e0a8e
commit
67cad91898
47 changed files with 1549 additions and 1 deletions
26
solutions/10/q1004/solution.go
Normal file
26
solutions/10/q1004/solution.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package q1004
|
||||
|
||||
func longestOnes(nums []int, k int) int {
|
||||
flipped := 0
|
||||
curLen, maxLen := 0, 0
|
||||
tail := 0
|
||||
|
||||
for i := range nums {
|
||||
curLen++
|
||||
if nums[i] == 0 {
|
||||
flipped++
|
||||
|
||||
for flipped > k {
|
||||
if nums[tail] == 0 {
|
||||
flipped--
|
||||
}
|
||||
tail++
|
||||
curLen--
|
||||
}
|
||||
}
|
||||
maxLen = max(maxLen, curLen)
|
||||
}
|
||||
return maxLen
|
||||
}
|
||||
|
||||
var _ = longestOnes
|
||||
Loading…
Add table
Add a link
Reference in a new issue