523. Continuous Subarray Sum

523. Continuous Subarray Sum

class Solution:
    def checkSubarraySum(self, nums: List[int], k: int) -> bool:
        seen,cur={0:-1},0
        for i,a in enumerate(nums):
            cur=(cur+a)%k
            if i-seen.setdefault(cur,i)>1:return True

        return False
        

余数

你可能感兴趣的:(leetcode)