/longestSubarray.py Secret
Last active
July 16, 2023 00:18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def longestSubarray(self, nums: List[int]) -> int: | |
j = ans = zero = 0 | |
for i in range(len(nums)): | |
if nums[i] == 0: zero += 1 | |
while zero > 1: | |
if nums[j] == 0: zero -= 1 | |
j += 1 | |
ans = max(ans, i - j) | |
return ans | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment