Skip to content

Commit dd3a60f

Browse files
authoredDec 10, 2024
Merge pull request #3764 from drxlx/1493-longest-subarray-of-1s-after-deleting-one-element
Create 1493-longest-subarray-of-1s-after-deleting-one-element.swift
2 parents 89a0029 + 6611623 commit dd3a60f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
func longestSubarray(_ nums: [Int]) -> Int {
3+
var zeroCount = 0
4+
var res = 0
5+
var l = 0
6+
7+
for r in 0..<nums.count {
8+
if nums[r] == 0 {
9+
zeroCount += 1
10+
}
11+
while zeroCount > 1 {
12+
if nums[l] == 0 {
13+
zeroCount -= 1
14+
}
15+
l += 1
16+
}
17+
res = max(res, r - l)
18+
}
19+
20+
return res
21+
}
22+
}

0 commit comments

Comments
 (0)
Please sign in to comment.