Skip to content

Commit 76598c1

Browse files
authored
Create partition-array-into-three-parts-with-equal-sum.py
1 parent 38bd1b4 commit 76598c1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def canThreePartsEqualSum(self, A):
6+
"""
7+
:type A: List[int]
8+
:rtype: bool
9+
"""
10+
total = sum(A)
11+
if total % 3 != 0:
12+
return False
13+
parts, curr = 0, 0
14+
for x in A:
15+
curr += x
16+
if curr == total//3:
17+
parts += 1
18+
curr = 0
19+
return parts >= 3

0 commit comments

Comments
 (0)