Problem
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example
1 | Given nums = [2, 7, 11, 15], target = 9, |
Methods: Brute Force, Hash Table
Solution 1
Method: Brute Force
Time Complexity: O(n^2)
Space Complexity: O(1)
1 | class Solution: |
Solution 2
Method: Hash Table
Time complexity: O(n)
Space complexity: O(n)
1 | class Solution: |