Java solution


  • 0
    T
    public boolean checkSubarraySum(int[] nums, int k) {
        for(int i = 0; i < nums.length; i++){
            int sum = nums[i];
            for(int j = i + 1; j < nums.length; j++){
                sum += nums[j];
                if(k!= 0 &&(sum >= k && sum % k == 0) ){
                    return true;
                } if( sum == 0){
                    return true;
                }
            }
        }
        return false;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.