MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / longestSubarray

Function longestSubarray

tasks/1493.go:9–25  ·  view source on GitHub ↗
(nums []int)

Source from the content-addressed store, hash-verified

7}
8
9func longestSubarray(nums []int) int {
10 var ret int
11 start, end := 0, 0
12 for prev := -1; start <= end && end < len(nums); end++ {
13 if nums[end] != 1 {
14 if prev == -1 {
15 prev = end
16 } else {
17 ret = max(ret, end-start-1)
18 start = prev + 1
19 prev = end
20 }
21 }
22 }
23 ret = max(ret, end-start-1)
24 return ret
25}
26
27func max(a, b int) int {
28 if a > b {

Callers 1

mainFunction · 0.85

Calls 1

maxFunction · 0.70

Tested by

no test coverage detected