class Solution {
public boolean checkSubarraySum(int[] nums, int k) {
int[] dp = new int[nums.length+1];
dp[0] = 0;
for(int i = 0;i<nums.length;i++){
dp[i+1] = dp[i] + nums[i];
}
for(int j = 0;j<nums.length -1;j++){
for(int m = j+1;m<nums.length;m++){
int sum = dp[m+1] - dp[j];
if (sum == k || (k != 0 && sum % k == 0)){
return true;
}
}
}
return false;
}
}
网友评论