-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path376.py
32 lines (29 loc) · 1.11 KB
/
376.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
__________________________________________________________________________________________________
sample 28 ms submission
class Solution:
def wiggleMaxLength(self, nums: List[int]) -> int:
if not nums:
return 0
length = 1
up = None
for i in range(1, len(nums)):
if nums[i] > nums[i - 1] and up != True:
length += 1
up = True
if nums[i] < nums[i - 1] and up != False:
length += 1
up = False
return length
__________________________________________________________________________________________________
sample 13008 kb submission
class Solution:
def wiggleMaxLength(self, nums: List[int]) -> int:
size = len(nums)
inc = dec = 1
for x in range(1, size):
if nums[x] > nums[x - 1]:
inc = dec + 1
elif nums[x] < nums[x - 1]:
dec = inc + 1
return max(inc, dec) if size else 0
__________________________________________________________________________________________________