Skip to content

Commit e031635

Browse files
authored
Create count-partitions-with-even-sum-difference.py
1 parent e07f3a6 commit e031635

File tree

1 file changed

+18
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)