数组 强化

1013. 将数组分成和相等的三个部分

思路:是否子数组和等于sum(A)的三分之一 ,如果有三个子数组则返回True。时间超越100%的python用户提交,内存超越100%的python用户提交

 1 class Solution(object):
 2     def canThreePartsEqualSum(self, A):
 3         if sum(A)%3!=0:
 4             return False
 5         node=sum(A)/3
 6         res=0
 7         number=0
 8         while A:
 9             res+=A.pop()
10             if res==node:
11                 res=0
12                 number+=1
13         return number==3

猜你喜欢

转载自www.cnblogs.com/xiaojiaojiao/p/10707020.html