Subarray Sum
https://leetcode.com/problems/continuous-subarray-sum/description/
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that is, sums up to n*k where n is also an integer.
Thoughts
求是否存在连续子数组的和能够整除k. 那我们可以把所有可能的子数组和遍历一遍。
Code
Analysis
Errors:
k = 0的情况没考虑
sum[i] % k == 0 没考虑
int j = i; j < n; j++ 顺序写反了
做题耗时20min
时间复杂度O(n^2).
Last updated
Was this helpful?