1. 程式人生 > >Leetcode 1013. Partition Array Into Three Parts With Equal Sum

Leetcode 1013. Partition Array Into Three Parts With Equal Sum

art part += def als seq false into equals

簡單題,暴力找出來就行.

class Solution:
    def canThreePartsEqualSum(self, A: List[int]) -> bool:
        s = sum(A)
        if s % 3 > 0:
            return False
        s /= 3
        size = len(A)
        t = 0
        a, b = -1, -1
        for i in range(size):
            t += A[i]
            
if t == s: a = i break t = 0 for j in range(size - 1, -1, -1): t += A[j] if t == s: b = j break if a == -1 or b == -1 or a + 1 >= b: return False return True

Leetcode 1013. Partition Array Into Three Parts With Equal Sum