Skip to content

Commit 548edf6

Browse files
committed
Time: 3 ms (26.38%), Space: 17.8 MB (69.5%) - LeetHub
1 parent 7ee747e commit 548edf6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# time complexity: O(n^2)
2+
# space complexity: O(1)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def countPartitions(self, nums: List[int]) -> int:
8+
count = 0
9+
for i in range(1, len(nums)):
10+
if (sum(nums[:i]) - sum(nums[i:])) % 2 == 0:
11+
count += 1
12+
return count
13+
14+
15+
nums = [10, 10, 3, 7, 6]
16+
print(Solution().countPartitions(nums))
17+
nums = [1, 2, 2]
18+
print(Solution().countPartitions(nums))
19+
nums = [2, 4, 6, 8]
20+
print(Solution().countPartitions(nums))

0 commit comments

Comments
 (0)