Last active
May 29, 2021 16:18
-
-
Save ikaruce/17caac78246ccd79f6719e0d4731a939 to your computer and use it in GitHub Desktop.
LeetCode 1. two sum
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
class Solution { | |
public int[] twoSum(int[] nums, int target) { | |
HashMap<Integer, Integer> h = new HashMap<Integer, Integer>(); | |
int i = 0; | |
for(; i< nums.length; i++){ | |
if(h.get(nums[i]) == null){ | |
h.put(target-nums[i], i); | |
}else{ | |
break; | |
} | |
} | |
return new int[] {i, h.get(nums[i])}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment