Skip to content

Instantly share code, notes, and snippets.

@Maggie199
Created January 19, 2015 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maggie199/783e32053d293eabc4bf to your computer and use it in GitHub Desktop.
Save Maggie199/783e32053d293eabc4bf to your computer and use it in GitHub Desktop.
Leetcode #1
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