523. Continuous Subarray Sum Medium
1/**
2 * [523] Continuous Subarray Sum
3 *
4 * 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.
5 * 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.
6 *
7 * Example 1:
8 *
9 * Input: nums = [23,<u>2,4</u>,6,7], k = 6
10 * Output: true
11 * Explanation: [2, 4] is a continuous subarray of size 2 whose elements sum up to 6.
12 *
13 * Example 2:
14 *
15 * Input: nums = [<u>23,2,6,4,7</u>], k = 6
16 * Output: true
17 * Explanation: [23, 2, 6, 4, 7] is an continuous subarray of size 5 whose elements sum up to 42.
18 * 42 is a multiple of 6 because 42 = 7 * 6 and 7 is an integer.
19 *
20 * Example 3:
21 *
22 * Input: nums = [23,2,6,4,7], k = 13
23 * Output: false
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= nums.length <= 10^5
29 * 0 <= nums[i] <= 10^9
30 * 0 <= sum(nums[i]) <= 2^31 - 1
31 * 1 <= k <= 2^31 - 1
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/continuous-subarray-sum/
37// discuss: https://leetcode.com/problems/continuous-subarray-sum/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn check_subarray_sum(nums: Vec<i32>, k: i32) -> bool {
43 false
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_523() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.