We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 101b6e1 commit f6ef448Copy full SHA for f6ef448
two-sum/dohee789.java
@@ -0,0 +1,20 @@
1
+/*
2
+https://leetcode.com/problems/two-sum/
3
+ */
4
+class Solution {
5
+ public int[] twoSum(int[] nums, int target) {
6
+ Map<Integer, Integer> map = new HashMap<>();
7
+ for(int i = 0; i < nums.length; i++){
8
+ map.put(nums[i], i);
9
+ }
10
+
11
12
+ if(map.containsKey(target - nums[i])
13
+ && map.get(target - nums[i]) != i){
14
+ int j = map.get(target - nums[i]);
15
+ return new int[]{i, j};
16
17
18
+ return null;
19
20
+}
0 commit comments