MCPcopy Create free account
hub / github.com/camilamaia/jornada-big-tech / twoSum

Method twoSum

leetcode/src/TwoSumLeetCodeSolution.java:3–17  ·  view source on GitHub ↗
(int[] nums, int target)

Source from the content-addressed store, hash-verified

1/** Problem: https://leetcode.com/explore/interview/card/google/59/array-and-strings/3049/ */
2class Solution {
3 public int[] twoSum(int[] nums, int target) {
4 Map<Integer, Integer> map = new HashMap<Integer, Integer>();
5
6 for (int i = 0; i < nums.length; i++) {
7 int complement = target - nums[i];
8
9 if (map.containsKey(complement)) {
10 return new int[] {map.get(complement), i};
11 }
12
13 map.put(nums[i], i);
14 }
15
16 return null;
17 }
18}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected