Created
September 2, 2019 23:07
-
-
Save wenweixu/1f1cd5ad3a0ae8a908c5aa5d41a65117 to your computer and use it in GitHub Desktop.
Hackerrank Pairs Python solution
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
# Complete the pairs function below. | |
def pairs(k, arr): | |
my_dict = {} | |
result = 0 | |
for ele in arr: | |
my_dict[ele] = 1 | |
if ele + k in my_dict: | |
result += 1 | |
if ele -k in my_dict: | |
result += 1 | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment