Advertisement
absolute100

Untitled

Apr 12th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. class Solution(object):
  2.     def findPairs(self, nums, k):
  3.         """
  4.        :type nums: List[int]
  5.        :type k: int
  6.        :rtype: int
  7.        """
  8.         n = len(nums)
  9.         nums.sort()
  10.         i,j = 0,1
  11.         cnt = 0
  12.         while j<n:
  13.             if i<n and i>0 and nums[i]==nums[i-1]:
  14.                 i+=1
  15.                 continue
  16.  
  17.             if j<=i or nums[j]-nums[i]<k:
  18.                 j+=1
  19.             elif nums[j]-nums[i]==k:
  20.                 cnt+=1
  21.                 i+=1
  22.             else:
  23.                 i+=1
  24.         return cnt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement