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.
1. brute force T: O(n ^2), S: O(1) classSolution:defsubarraySum(self, nums: List[int], target: int) ->int: n, count=len(nums), 0foriinrange(n):forjinrange(i, n): curSum= sum(nums[i: j + 1])ifcurSum ==target: count+= 1returncount 2. 参考Prefix Sum & Dictionary ...
[LeetCode] 2536. Increment Submatrices by One CNoodle 2023-01-17 02:43 阅读:140 评论:0 推荐:0 [LeetCode] 2281. Sum of Total Strength of Wizards CNoodle 2023-01-13 06:40 阅读:140 评论:0 推荐:0 1 2 3 下一页 公告 昵称: CNoodle 园龄: 5年7个月 粉丝: 11 关注: 13 +加关注...
FindHeaderBarSize FindTabBarSize 有一个书店老板,他的书店开了n分钟。每分钟都有一些顾客进入这家商店。给定一个长度为n的整数数组customers,其中customers[i]是在第i分钟开始时进入商店的顾客数量,所有这些顾客在第i分钟结束后离开。 在某些分钟内,书店老板会生气。 如果书店老板在第i分钟生气,那么grumpy[i] = ...
这道题最普通的解法就是每次调用sumRange方法时,就做遍历相加。但是,这样的话,算法的时间复杂度就会是O(n)O(n)。如果使用前缀和,则能将时间复杂度降低到O(1)O(1)。只不过,需要使用额外的空间,复杂度为:O(n)O(n)。 图2. LeetCode 303. 区域和检索 ...