<reponame>lyuhaitao/lyuAlgorithm
# AUTOGENERATED! DO NOT EDIT! File to edit: 00_core.ipynb (unless otherwise specified).

__all__ = ['twoNumberSum', 'twoNumberSumHarshTable', 'twoNumberSumPoints']

# Cell
def twoNumberSum(array, targetSum):
    n = len(array)
    for i in range(n - 1):
        for j in range(i+1, n):
            if array[i] + array[j] == targetSum:
                return [array[i], array[j]]
    return []

# Cell
def twoNumberSumHarshTable(array, targetSum):
    nums = []
    for i in array:
        n = targetSum - i
        if n in nums:
            return [i,n]
        else:
            nums.append(i)
    return []

# Cell
def twoNumberSumPoints(array, targetSum):
    left = 0; right = len(array)-1
    array.sort()
    sa = array
    while left < right:
        n = sa[left] + sa[right]
        if n > targetSum: # move to left
            right = right - 1
        elif n < targetSum: # move to right
            left += 1
        else:
            return [sa[left], sa[right]]
    return []

# AUTOGENERATED! DO NOT EDIT! File to edit: 00_core.ipynb (unless otherwise specified).

__all__ = ['twoNumberSum', 'twoNumberSumHarshTable', 'twoNumberSumPoints']

# Cell
def twoNumberSum(array, targetSum):
    n = len(array)
    for i in range(n - 1):
        for j in range(i+1, n):
            if array[i] + array[j] == targetSum:
                return [array[i], array[j]]
    return []

# Cell
def twoNumberSumHarshTable(array, targetSum):
    nums = []
    for i in array:
        n = targetSum - i
        if n in nums:
            return [i,n]
        else:
            nums.append(i)
    return []

# Cell
def twoNumberSumPoints(array, targetSum):
    left = 0; right = len(array)-1
    array.sort()
    sa = array
    while left < right:
        n = sa[left] + sa[right]
        if n > targetSum: # move to left
            right = right - 1
        elif n < targetSum: # move to right
            left += 1
        else:
            return [sa[left], sa[right]]
    return []
# AUTOGENERATED! DO NOT EDIT! File to edit: 00_core.ipynb (unless otherwise specified). # Cell # Cell # Cell # move to left # move to right