MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / twoSum

Method twoSum

src/com/blankj/easy/_0001/Solution.java:26–37  ·  view source on GitHub ↗
(int[] nums, int target)

Source from the content-addressed store, hash-verified

24// }
25
26 public int[] twoSum(int[] nums, int target) {
27 int len = nums.length;
28 HashMap<Integer, Integer> map = new HashMap<>();
29 for (int i = 0; i < len; ++i) {
30 final Integer value = map.get(nums[i]);
31 if (value != null) {
32 return new int[] { value, i };
33 }
34 map.put(target - nums[i], i);
35 }
36 return null;
37 }
38
39 public static void main(String[] args) {
40 Solution solution = new Solution();

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected