当前位置:网站首页>523. Continuous Subarray Sum
523. Continuous Subarray Sum
2022-06-23 08:46:00 【ujn20161222】
523. Continuous Subarray Sum
Medium
1647228Add to ListShare
Given an integer array nums and an integer k, return true if nums has a continuous subarray of size at least two whose elements sum up to a multiple of k, or false otherwise.
An integer x is a multiple of k if there exists an integer n such that x = n * k. 0 is always a multiple of k.
Example 1:
Input: nums = [23,2,4,6,7], k = 6 Output: true Explanation: [2, 4] is a continuous subarray of size 2 whose elements sum up to 6.
Example 2:
Input: nums = [23,2,6,4,7], k = 6 Output: true Explanation: [23, 2, 6, 4, 7] is an continuous subarray of size 5 whose elements sum up to 42. 42 is a multiple of 6 because 42 = 7 * 6 and 7 is an integer.
Example 3:
Input: nums = [23,2,6,4,7], k = 13 Output: false
Constraints:
1 <= nums.length <= 1050 <= nums[i] <= 1090 <= sum(nums[i]) <= 231 - 11 <= k <= 231 - 1
Accepted
277,174
Submissions
1,024,226
class Solution:
def checkSubarraySum(self, nums: List[int], k: int) -> bool:
d=defaultdict(list)
for i, sm in enumerate([0]+list(accumulate(nums))):
d[sm%k]+=[i]
for val in d:
if d[val][-1]-d[val][0]>=2: return True
return Falsed The index corresponding to the remainder is stored in the
Then judge the interval
边栏推荐
- Summary of Arthas vmtool command
- Go data types (II) overview of data types supported by go and Boolean types
- 7-调色板-CALayer和触摸
- Talk about the implementation principle of @autowired
- In June, China database industry analysis report was released! Smart wind, train storage and regeneration
- [QNX Hypervisor 2.2用户手册]6.2 网络
- kernel log调试方法
- How thingjs enables low threshold 3D visualization development
- 词性家族
- Map (set) operation in go language
猜你喜欢

测试-- 自动化测试selenium(关于API)

Linux Mysql安装

给你的win10装一个wget

6月《中國數據庫行業分析報告》發布!智能風起,列存更生

最常用的5中流ETL模式

297. Serialize and Deserialize Binary Tree
![Paper reading [quovadis, action recognition? A new model and the dynamics dataset]](/img/3f/449cc91bfa66fcf26bc2cd405fb773.png)
Paper reading [quovadis, action recognition? A new model and the dynamics dataset]

Data assets are king, analyzing the relationship between enterprise digital transformation and data asset management

Object.defineProperty() 和 数据代理

PCB电路板特性检查项目都有哪些?
随机推荐
Isomorphic strings for leetcode topic resolution
6-闪耀的激光-CALayer 的应用
Open source technology exchange batch stream integrated data synchronization engine Chunjun data restore DDL function module analysis
173. Binary Search Tree Iterator
Lighthouse cloud desktop experience
Leetcode topic analysis spiral matrix II
Can portals be the next decentraland?
[cloud computing] GFS ideological advantages and architecture
Arthas vmtool命令小结
Leetcode topic analysis count primes
谈谈 @Autowired 的实现原理
125. Valid Palindrome
Set interface and set sub implementation classes
65. Valid Number
Driver Architecture & platform platform bus driver model
Hongmeng reads the resource file
'教练,我想打篮球!' —— 给做系统的同学们准备的 AI 学习系列小册
438. Find All Anagrams in a String
Spirit matrix for leetcode topic analysis
RTSP/ONVIF协议视频平台EasyNVR启动服务报错“service not found”,该如何解决?