-
Notifications
You must be signed in to change notification settings - Fork 0
/
376.py
51 lines (40 loc) · 1.28 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = ['"wuyadong" <[email protected]>']
class Solution(object):
def wiggleMaxLength(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n = len(nums)
if n <= 0:
return 0
bs = [0]
count = [1]
for i in xrange(1, n):
max_c = 1
max_b = 0
for j in xrange(0, i):
if nums[j] > nums[i] and bs[j] >= 0:
c = count[j] + 1
b = -1
elif nums[j] < nums[i] and bs[j] <= 0:
c = count[j] + 1
b = 1
else:
c = None
if c is not None:
if c > max_c:
max_c = c
max_b = b
elif c == max_c & b * max_b == -1:
max_b = 0
bs.append(max_b)
count.append(max_c)
return max(count)
if __name__ == "__main__":
# print Solution().wiggleMaxLength([1,7,4,9,2,5])
# print Solution().wiggleMaxLength([1,17,5,10,13,15,10,5,16,8])
# print Solution().wiggleMaxLength([1,2,3,4,5,6,7,8,9])
print Solution().wiggleMaxLength([0, 0])