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> h = new HashMap<>();
- for (int i = 0; i < nums.length; i++) {
- if (h.containsKey(nums[i])) {
- return new int[]{h.get(nums[i]), i};
- }
- h.put(target-nums[i], i);
- }
- return new int[0];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement