Quick actions

cmd+k|ctrl+k

Navigation

Languages

has pair with sum

Snippet info

Language

Python

Visibility

public

Author

shawnxiao1229

Created

2019-05-26T01:13:27Z

Updated

2019-05-26T01:13:27Z

def hasPairWithSum(arr, s):
    # create a dictionary / set which contains the value of the sum - arr[i]
    findSet = set()
    for i in arr:
        if i in findSet:
            return True
        else:
            findSet.add(s-i)
    return False


a = hasPairWithSum([1,5,4,5], null)
print(a)

INFO