Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int subarraySum(int[] nums, int k) {
- int count = 0;
- for (int i = 0; i < nums.length; i++)
- {
- if (nums[i] == k)
- {
- count++;
- }
- }
- for (int i = 0; i < nums.length - 1; i++)
- {
- int sum = nums[i];
- for (int j = i+1; j < nums.length; j++)
- {
- sum += nums[j];
- if (sum == k)
- {
- count++;
- }
- }
- }
- return count;
- }
- }
Add Comment
Please, Sign In to add comment