View difference between Paste ID: 50fKArx5 and WF0rQVEc
SHOW: | | - or go back to the newest paste.
1
class Solution {
2
    public int subarraySum(int[] nums, int k) {
3
        int count = 0;
4
        for (int i = 0; i < nums.length; i++)
5
        {
6
            if (nums[i] == k)
7
            {
8
                count++;
9
            }
10
        }
11
        for (int i = 0; i < nums.length - 1; i++)
12
        {
13
            int sum = nums[i];
14
            for (int j = i+1; j < nums.length; j++)
15
            {
16
                sum += nums[j];
17
                if (sum == k)
18
                {
19
                    count++;
20
                }
21
            }
22
        }
23
        return count;
24
    }
25
}