classSolution {publicbooleancheckSubarraySum(int[] nums,int k) {int sum =0;Map<Integer,Integer> map =newHashMap<>();map.put(0,-1);for (int i =0; i <nums.length; i++) { sum += nums[i]; sum %= k; // store remainder!if (map.containsKey(sum)) {if (i -map.get(sum) >1) { // means keep the previous sum index, not update same sum with latest ireturntrue; } } else {map.put(sum, i); // only when not in map, update the index (for keeping the oldest index to make longer dist) } }returnfalse; }}/***T: O(n)S: O(n)0. 1 223 2 4set(23, 25, 29)23%6 = 55 015 */