LeetCode题解(0930):和相同的二元子数组(Python)
发布日期:2021-06-29 20:09:35 浏览次数:4 分类:技术文章

本文共 453 字,大约阅读时间需要 1 分钟。

题目:(中等)

标签:哈希表、双指针

解法 时间复杂度 空间复杂度 执行用时
Ans 1 (Python) O ( N ) O(N) O(N) O ( N ) O(N) O(N) 304ms (81.07%)
Ans 2 (Python)
Ans 3 (Python)

解法一:

class Solution:    def numSubarraysWithSum(self, A: List[int], S: int) -> int:        count = collections.Counter({
0: 1}) ans = 0 last = 0 for n in A: last += n if last - S in count: ans += count[last - S] count[last] += 1 return ans

转载地址:https://dataartist.blog.csdn.net/article/details/109839171 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LeetCode题解(0939):最小面积矩形(Python)
下一篇:LeetCode题解(0781):森林中的兔子(Python)

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月18日 09时13分35秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章