遍历所有长度=2的连续子序列,满足条件返回,仅过93/95个测试用例,到最后时间超了 class Solution : def checkSubarraySum ( self , nums : List [ int ], k : int ) - bool : if len ( nums ) 2 : return False left =
遍历所有长度>=2的连续子序列,满足条件返回,仅过93/95个测试用例,到最后时间超了
def checkSubarraySum(self, nums: List[int], k: int) -> bool:
if len(nums) < 2:
return False
left = 0
while left <= len(nums)-2:
s = nums[left]
for j in range(left+1,len(nums)):
s += nums[j]
if s % k == 0:
return True
left += 1
return False