Created
January 19, 2015 15:10
-
-
Save Maggie199/783e32053d293eabc4bf to your computer and use it in GitHub Desktop.
Leetcode #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Hashtable; | |
public class Solution { | |
public int[] twoSum(int[] numbers, int target) { | |
Hashtable<Integer, Integer> check = new Hashtable<Integer, Integer>(); | |
for(int i = 0; i<numbers.length;i++){ | |
if(check.containsKey(target-numbers[i])) | |
return new int[]{check.get(target-numbers[i]),i+1}; | |
else check.put(numbers[i],i+1); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment