vladimirVenkov

Subarray sum Equals K svetoslav

Jun 18th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
Add Comment
Please, Sign In to add comment