From c832f51587b689fc12ee0a5943d581b095a6dabf Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Sun, 15 Nov 2020 09:16:45 +0100 Subject: Task 1 Challenge 086 LK refactor --- challenge-086/lubos-kolouch/python/ch-1.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'challenge-086/lubos-kolouch/python/ch-1.py') diff --git a/challenge-086/lubos-kolouch/python/ch-1.py b/challenge-086/lubos-kolouch/python/ch-1.py index 0f284bf4c6..ffeda9b648 100644 --- a/challenge-086/lubos-kolouch/python/ch-1.py +++ b/challenge-086/lubos-kolouch/python/ch-1.py @@ -20,16 +20,14 @@ def is_pair_difference(n: list, a: int): """ # to avoid sorting and/or scanning through all pairs in the array # or double nested loop, - # I will convert the array to a hash, then check if the - # corresponding key exists + # I will convert the array to a hash and check it on the fly """ hash_keys = {} for number in n: hash_keys[number] = 1 - for x in hash_keys: - if hash_keys.get(x+a, 0): + if hash_keys.get(number+a, 0) or hash_keys.get(number-a, 0): return 1 return 0 -- cgit