파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 10. 26. 23:45

https://leetcode.com/problems/continuous-subarray-sum/

 

Continuous Subarray Sum - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

해시맵을 활용하면 쉽게 풀림.

class Solution:
    def checkSubarraySum(self, nums: List[int], k: int) -> bool:
        m = {0: 0}
        s = 0
        for i in range(len(nums)):
            s += nums[i]
            if s % k not in m:
                m[s % k] = i + 1
            elif m[s % k] < i:
                return True
        return False
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.10.28
Today's Challenge  (0) 2022.10.27
Today's Challenge  (0) 2022.10.25
Today's Challenge  (0) 2022.10.24
Today's Challenge  (0) 2022.10.23
Comments