The code first checks if k is zero. If it is, the only case that would return true is if there were at least two consecutive zeros. If, however, k is not zero, iterate through the list and calculate the cumulative "mod sum" up to index i (i.e. cumulative sum MOD k). If we've seen this mod sum before, then it means we have a contiguous subarray whose sum MOD k is zero.

```
public boolean checkSubarraySum(int[] nums, int k) {
if (k == 0) {
boolean prevZero = false;
for (int i=0; i<nums.length; i++) {
if (prevZero && nums[i] == 0) return true;
prevZero = nums[i] == 0;
}
} else {
Set<Integer> remainders = new HashSet<>();
int modSum = 0;
for (int i=0; i<nums.length; i++) {
modSum = (modSum + nums[i]) % k;
if (modSum == 0 && i != 0) return true;
if (remainders.contains(modSum)) return true;
remainders.add(modSum);
}
}
return false;
}
```