package com.sid.leetcode;

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

/**
 * 1. Two Sum.
 *
 * <blockquote>
 * Given an array of integers, return <b>indices</b> of the two numbers such that they add up to a specific target.
 * <p>You may assume that each input would have <b><i>exactly</i></b> one solution.
 * <p><b>Example</b>:
 * <blockquote>
 * Given nums = [2, 7, 11, 15], target = 9,
 * <p>Because nums[<b>0</b>] + nums[<b>1</b>] = 2 + 7 = 9, return [<b>0</b>, <b>1</b>].
 * </blockquote>
 *
 * <p><font color='red'><b>UPDATE (2016/2/13):</b></font>
 * <p>The return format had been changed to <b>zero-based</b> indices. Please read the above updated description carefully.
 * 
 * </blockquote>
 *
 * @author Sid.Chen
 * @version 1.0, 2016-07-09
 *
 */
public class A0001_TwoSum {

	public int[] twoSum(int[] nums, int target) {
		Map<Integer, Integer> mapping = new HashMap<Integer, Integer>();
		for (int i = 0; i < nums.length; i++) {
			int other = target - nums[i];
			if (mapping.containsKey(other)) {
				return new int[] { mapping.get(other), i };
			}
			mapping.put(nums[i], i);
		}
		return null;
	}

}

@@ -305,16 +305,60 @@
 solution
+, and you may not use the same element twice
 .%0A * %3Cp%3E
@@ -542,197 +542,8 @@
 te%3E%0A
- *%0A * %3Cp%3E%3Cfont color='red'%3E%3Cb%3EUPDATE (2016/2/13):%3C/b%3E%3C/font%3E%0A * %3Cp%3EThe return format had been changed to %3Cb%3Ezero-based%3C/b%3E indices. Please read the above updated description carefully.%0A * %0A
  * %3C
@@ -663,16 +663,22 @@
  twoSum(
+final 
 int%5B%5D nu
@@ -680,16 +680,22 @@
 %5B%5D nums,
+ final
  int tar
@@ -703,16 +703,22 @@
 et) %7B%0A%09%09
+final 
 Map%3CInte
@@ -734,20 +734,16 @@
 ger%3E map
-ping
  = new H
@@ -815,16 +815,22 @@
 +) %7B%0A%09%09%09
+final 
 int othe
@@ -861,20 +861,16 @@
 %09if (map
-ping
 .contain
@@ -910,20 +910,16 @@
 %5B%5D %7B map
-ping
 .get(oth
@@ -943,12 +943,8 @@
 %09map
-ping
 .put

Clean up #1 Two Sum