You are viewing a single comment's thread. Return to all comments →
Nice and simple with Javascript, after sorting the numbers.
var i=0,j=1,count=0; while(j < n) { var diff = nums[j] - nums[i]; if (diff == k) { count++; j++; } else if (diff > k) { i++; } else if (diff < k) { j++; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all comments →
Nice and simple with Javascript, after sorting the numbers.