Skip to content

Commit 09ce693

Browse files
committedAug 29, 2023
solution: 1493. Longest Subarray of 1's After Deleting One Element
1 parent 603028a commit 09ce693

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed
 

‎solutions/solution_1493/__init__.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,18 @@
33

44
class Solution:
55
def longestSubarray(self, nums: List[int]) -> int:
6-
...
6+
left = 0
7+
zero_count = 0
8+
max_length = 0
9+
for right in range(len(nums)):
10+
if nums[right] == 0:
11+
zero_count += 1
12+
13+
while zero_count > 1:
14+
if nums[left] == 0:
15+
zero_count -= 1
16+
left += 1
17+
18+
max_length = max(max_length, right - left)
19+
20+
return max_length

0 commit comments

Comments
 (0)
Please sign in to comment.