Skip to content

Commit b784332

Browse files
committed
v1: error, i + 1写成1 + 1了
1 parent d85050f commit b784332

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2024-01-23 22:22:14
4+
LastEditors: LetMeFly
5+
LastEditTime: 2024-01-23 22:25:36
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def get1(self, oddLoc=1) -> int:
11+
evenLoc = -oddLoc
12+
ans = 1
13+
cnt = 1
14+
for i in range(len(self.nums)):
15+
shouldAdd = oddLoc if i % 2 else evenLoc
16+
if 1 + 1 == len(self.nums) or self.nums[i + 1] != self.nums[i] + shouldAdd or (cnt == 1 and shouldAdd == -1):
17+
ans = max(ans, cnt)
18+
cnt = 1
19+
else:
20+
cnt += 1
21+
return ans
22+
23+
def alternatingSubarray(self, nums: List[int]) -> int:
24+
self.nums = nums
25+
ans = max(self.get1(), self.get1(-1))
26+
return ans if ans >= 2 else -1

0 commit comments

Comments
 (0)