Skip to content

Instantly share code, notes, and snippets.

@h0lybyte
Last active September 29, 2020 22:49
Show Gist options
  • Save h0lybyte/ca09ca4d2a059da5bf976c92eaf49680 to your computer and use it in GitHub Desktop.
Save h0lybyte/ca09ca4d2a059da5bf976c92eaf49680 to your computer and use it in GitHub Desktop.
Leetcode #1
class Solution {
public int[] twoSum(int[] nums, int target) {
HashMap<Integer, Integer> box = new HashMap<Integer, Integer>();
for(int _index = 0 ; _index < nums.length; _index++ )
{
if(box.size() >= 1)
{
if(box.containsKey(target - nums[_index]))
{
return new int[] {box.get(target - nums[_index]), _index} ;
}
}
box.put(nums[_index], _index);
}
return new int[] { 0, 0 };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment