Skip to content

Commit c200807

Browse files
authored
Create maximum-split-of-positive-even-integers.py
1 parent 575e80f commit c200807

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time: O(sqrt(n))
2+
# Space: O(1)
3+
4+
# greedy
5+
class Solution(object):
6+
def maximumEvenSplit(self, finalSum):
7+
"""
8+
:type finalSum: int
9+
:rtype: List[int]
10+
"""
11+
if finalSum%2:
12+
return []
13+
result = []
14+
i = 2
15+
while i <= finalSum:
16+
result.append(i)
17+
finalSum -= i
18+
i += 2
19+
result[-1] += finalSum
20+
return result

0 commit comments

Comments
 (0)