Skip to content

Commit 25c1974

Browse files
authoredAug 22, 2024
1493. Longest Subarray of 1's After Deleting One Element
1 parent b75cbbd commit 25c1974

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
 
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
fun longestSubarray(nums: IntArray): Int {
3+
var maxLength = 0
4+
var left = 0
5+
var zeros = 0
6+
7+
for (i in nums.indices){
8+
if(nums[i] == 0){
9+
zeros ++
10+
}
11+
while(zeros > 1){
12+
if(nums[left] == 0){
13+
zeros --
14+
}
15+
left++
16+
}
17+
maxLength = maxOf(maxLength, i - left)
18+
}
19+
return maxLength
20+
}
21+
22+
}

0 commit comments

Comments
 (0)
Please sign in to comment.