Skip to content

560. Subarray Sum Equals K#34

Open
hiro111208 wants to merge 2 commits into
mainfrom
560-subarray-sum-equals-k
Open

560. Subarray Sum Equals K#34
hiro111208 wants to merge 2 commits into
mainfrom
560-subarray-sum-equals-k

Conversation

@hiro111208
Copy link
Copy Markdown
Owner

This problem: 560. Subarray Sum Equals K

Next problem: 49. Group Anagrams


空間計算量: $O(1)$

- しかし上記ではTime Limit Exceededになった。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらのコメントをご参照ください。
Yuto729/leetcode#16

class Solution:
def subarraySum(self, nums: List[int], k: int) -> int:
prefix_sum_to_count = {0: 1}
prefix_sum = 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

細かいですが、

        prefix_sum = 0
        prefix_sum_to_count = {0: 1}

の順番のほうが読みやすいです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants