/**
 * Name: Two Sum
 * Number: 1
 * Tag: Array
 * Main Points: use a hashmap to store
 * Time Complexity: O(n)
 * Space Complexity: O(n)
**/
class Solution {
    public int[] twoSum(int[] nums, int target) {
        int[] ans = new int[2];
        if (nums == null || nums.length == 0) return ans;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i])) { //containsKey O(1)
                ans[0] = map.get(target - nums[i]);
                ans[1] = i;
                return ans;
            } 
            map.put(nums[i], i);  //put O(1)          
        }
        return ans;    
    }
}
@@ -85,78 +85,369 @@
 re%0A 
-* Time Complexity: O(n)%0A * Space Complexity: O(n)%0A**/%0Aclass Solution %7B
+  2 ways come into mind:%0A   (1) brute force (TC:O(n%5E2), SC:O(1))%0A   (3) HashMap (TC: O(n), SC:O(n))%0A * Time Complexity: O(n)%0A * Space Complexity: O(n)%0A * Follow up: %0A   if we need to output the numbers rather than indices%0A   hashmap works, 2 pointers also works(TC: O(nlogn), SC:O(1))%0A**/%0Aclass Solution %7B%0A    /******************** HashMap ********************/
 %0A   
@@ -974,9 +974,14 @@
  %0A    %7D%0A
+    %0A
 %7D

add Follow up