Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4c20676

Browse files
committed
Time: 105 ms (35.66%) | Memory: 39.2 MB (54.26%) - LeetSync
1 parent 752f50c commit 4c20676

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution:
2+
def maximumLength(self, nums: List[int]) -> int:
3+
if len(nums) == 2:
4+
return 2
5+
cnt_odd = 0
6+
cnt_even = 0
7+
cnt_even_odd = 0
8+
cnt_odd_even = 0
9+
odv = None
10+
evod = None
11+
for i in range(len(nums)):
12+
if nums[i] % 2 ==0:
13+
cnt_even +=1
14+
if evod is None or evod%2 !=nums[i] %2:
15+
cnt_even_odd +=1
16+
evod = nums[i]
17+
if odv is None or odv % 2 !=nums[i]%2:
18+
cnt_odd_even +=1
19+
odv = nums[i]
20+
21+
else:
22+
cnt_odd +=1
23+
if odv is None or odv % 2 !=nums[i]%2:
24+
cnt_odd_even +=1
25+
odv = nums[i]
26+
if evod is None or evod%2 !=nums[i] %2:
27+
cnt_even_odd +=1
28+
evod = nums[i]
29+
return max(cnt_odd, cnt_even, cnt_odd_even, cnt_even_odd)
30+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /