Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int[] twoSum(int[] nums, int target) {
- HashMap<Integer, Integer> stuff = new HashMap<>();
- for (int i=0; i<nums.length; i++){
- stuff.put(nums[i], i);
- }
- for (int i=0; i<nums.length; i++){
- if (stuff.containsKey(target-nums[i]) ){
- int otherIndex = stuff.get(target-nums[i]);
- if (i == otherIndex){
- continue;
- }
- int returnVal[] = {i, otherIndex};
- return returnVal;
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement