Java solution, easy understanding


  • 0
    W

    public class Solution {
    public int subarraySum(int[] nums, int k) {

       int M=0;
       int count=0;
       int len=nums.length;
       while(M<len){
           
        int N=M;
        int sum=0;
       while(N<len){
           sum+=nums[N];
           if(sum==k){
               count++;
           }
           N++;
       }
       M++;
       }
       return count;
    }
    

    }


Log in to reply
 

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