fork download
  1. # your code goes here
  2.  
  3. class Solution(object):
  4. def countSubarrays(self, nums, k):
  5. """
  6. :type nums: List[int]
  7. :type k: int
  8. :rtype: int
  9. """
  10.  
  11. i = 0
  12. s = 0
  13. ans=0
  14. for j in range(len(nums)):
  15. s = s+nums[j]
  16. l = j-i+1
  17. while s >= k:
  18. s=s-nums[i]
  19. i=i+1
  20. ans+=j-i+1
  21.  
  22. return ans
  23.  
  24.  
  25.  
Success #stdin #stdout 0.07s 13976KB
stdin
Standard input is empty
stdout
Standard output is empty