leetcode——327. 区间和的个数
作者:互联网
超出时间了。。。
class Solution(object): def countRangeSum(self, nums, lower, upper): """ :type nums: List[int] :type lower: int :type upper: int :rtype: int """ i=0 n=0 while i<len(nums): j=i while j<len(nums): s=sum(nums[i:j+1]) if s>=lower and s<=upper: n+=1 j+=1 else: if s>upper: j+=1 while j<len(nums) and nums[j]>=0: j+=1 elif s<lower: j+=1 while j<len(nums) and nums[j]<=0: j+=1 i+=1 return n
标签:upper,lower,nums,int,个数,while,327,type,leetcode 来源: https://www.cnblogs.com/taoyuxin/p/11831085.html