Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main.java.twosum;
- import java.util.*;
- public class TwoSum {
- public int[] twoSum(int[] nums, int target) {
- Map<Integer, Integer> map = new HashMap<Integer, Integer>();
- for (int i = 0; i < nums.length; i++) {
- if (map.containsKey(nums[i])) {
- return new int[]{i, map.get(nums[i])};
- }
- map.put(target - nums[i], i);
- }
- return new int[]{-1, -1};
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement