# Array, HashTable

class Solution:
    # time complexity: O(n), Space complexity:O(n)
    def twoSum(self, nums, target: int):
        hashmap = {num:i for i, num in enumerate(nums)}
        for i, num in enumerate(nums):
            x = target-num
            if hashmap.get(x, i) != i:
                return [i, hashmap[x]]
        return False

import unittest
class UnitTest(unittest.TestCase):
    solution = Solution()
    def test_case_normal(self):
        nums = [2, 7, 11, 15]
        target = 9
        self.assertListEqual(self.solution.twoSum(nums, target), [0, 1])
    
    def test_with_same_element(self):
        nums = [3, 2, 4]
        target = 6
        self.assertListEqual(self.solution.twoSum(nums, target), [1, 2])

unittest.main()
# Array, HashTable

class Solution:
    # time complexity: O(n), Space complexity:O(n)
    def twoSum(self, nums, target: int):
        hashmap = {num:i for i, num in enumerate(nums)}
        for i, num in enumerate(nums):
            x = target-num
            if hashmap.get(x, i) != i:
                return [i, hashmap[x]]
        return False

import unittest
class UnitTest(unittest.TestCase):
    solution = Solution()
    def test_case_normal(self):
        nums = [2, 7, 11, 15]
        target = 9
        self.assertListEqual(self.solution.twoSum(nums, target), [0, 1])
    
    def test_with_same_element(self):
        nums = [3, 2, 4]
        target = 6
        self.assertListEqual(self.solution.twoSum(nums, target), [1, 2])

unittest.main()
# Array, HashTable # time complexity: O(n), Space complexity:O(n)