523.Continuous Subarray Sum Posted on 2017-09-13 | In LeetCode Test Cases12345678910[1,5]-6[23, 2, 4, 6, 7]6[23 ,2, 4, 6, 7]0[0, 0]0[0, 0]100 Solution 1: accepted 29%Time: O(n^2)Brute force with double loops 12345678910111213141516171819202122232425public boolean checkSubarraySum(int[] nums, int k) { int len = nums.length; if (len < 2) return false; // Only if all elements in nums are 0, can k be 0 if (k == 0) { for (int n : nums) { if (n != 0) return false; } return true; } // Double loop to check all possible combinations for (int i = 0; i < len - 1; i++) { int sum = nums[i]; for (int j = i + 1; j < len; j++) { if ((sum + nums[j]) % k == 0) return true; sum += nums[j]; } } return false; }