Leetcode 1062 Solution

This article provides solution to leetcode question 1062 (partition-array-into-three-parts-with-equal-sum)

https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum

Solution

class Solution(object):
    def canThreePartsEqualSum(self, A):
        """
        :type A: List[int]
        :rtype: bool
        """
        s = sum(A)
        if s % 3 != 0:
            return False

        cur = 0
        part = 0
        for a in A:
            cur += a

            if cur == s / 3:
                cur = 0
                part += 1

        return part >= 3