package com.fishercoder.solutions;

import java.util.HashMap;
import java.util.Map;

/**
 * 1. Two Sum
 * <p>
 * Given an array of integers, return indices of the two numbers such that they add up to a specific target.
 * <p>
 * You may assume that each input would have exactly one solution, and you may not use the same element twice.
 * <p>
 * Example:
 * Given nums = [2, 7, 11, 15], target = 9,
 * <p>
 * Because nums[0] + nums[1] = 2 + 7 = 9,
 * return [0, 1].
 */
public class _1 {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap();
        int[] result = new int[2];
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i])) {
                result[0] = map.get(target - nums[i]);
                result[1] = i;
                break;
            } else {
                map.put(nums[i], i);
            }
        }
        return result;
    }

}

@@ -98,20 +98,16 @@
 o Sum%0A *
- %3Cp%3E
 %0A * Give
@@ -208,23 +208,16 @@
 target.%0A
- * %3Cp%3E%0A
  * You m
@@ -319,23 +319,16 @@
  twice.%0A
- * %3Cp%3E%0A
  * Examp
@@ -379,15 +379,8 @@
  9,%0A
- * %3Cp%3E%0A
  * B
@@ -458,16 +458,56 @@
 s _1 %7B%0A%0A
+    public static class Solution1 %7B%0A    
     publ
@@ -556,16 +556,20 @@
         
+   
+ 
 Map%3CInte
@@ -611,16 +611,20 @@
         
+    
 int%5B%5D re
@@ -650,16 +650,20 @@
         
+ 
+   
 for (int
@@ -690,24 +690,28 @@
 gth; i++) %7B%0A
+    
             
@@ -763,24 +763,28 @@
             
+    
 result%5B0%5D = 
@@ -822,24 +822,28 @@
             
+  
+  
 result%5B1%5D = 
@@ -845,16 +845,20 @@
 1%5D = i;%0A
+    
         
@@ -884,16 +884,20 @@
         
+    
 %7D else %7B
@@ -913,16 +913,20 @@
         
+  
+  
 map.put(
@@ -942,32 +942,36 @@
 i);%0A            
+    
 %7D%0A        %7D%0A    
@@ -964,26 +964,32 @@
         
+ 
-%7D%0A
+   %7D%0A  
         
 return r
@@ -980,16 +980,18 @@
         
+  
 return r
@@ -997,16 +997,26 @@
 result;%0A
+        %7D%0A
     %7D%0A%0A%7D

refactor 1