Skip to content

Commit 3e35355

Browse files
authored
Create maximum-alternating-subsequence-sum.py
1 parent 7717392 commit 3e35355

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def maxAlternatingSum(self, nums):
6+
"""
7+
:type nums: List[int]
8+
:rtype: int
9+
"""
10+
result = nums[0]
11+
for i in xrange(len(nums)-1):
12+
result += max(nums[i+1]-nums[i], 0)
13+
return result

0 commit comments

Comments
 (0)