Created
January 13, 2017 00:31
-
-
Save amandaclarck/36496a7598638b6622797f3807cb994b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pairs( a,k) | |
x = 0 | |
#y = 0 | |
resp = 0 | |
m = a.length.to_i | |
while x < a.length | |
y = m - 1 | |
while y < m | |
#puts y | |
if((a[y] - a[x])==k) | |
resp +=1 | |
end | |
y-=1 | |
if(y < 0) | |
break | |
end | |
end | |
x+=1 | |
end | |
return resp | |
end | |
#pairs([1,5,3,4,2],2) | |
pairs([2,3],1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment