leetcode1013】的更多相关文章

Given an array A of integers, return true if and only if we can partition the array into three non-emptyparts with equal sums. Formally, we can partition the array if we can find indexes i+1 < j with (A[0] + A[1] + ... + A[i] == A[i+1] + A[i+2] + ...…
class Solution(object): def canThreePartsEqualSum(self, A: 'List[int]') -> bool: n = len(A) sums = sum(A) if sums % 3 != 0: return False target = sums // 3 leftpart = 0 leftboundary = n -1 for i in range(n-2): leftpart += A[i] if leftpart == target:…