Skip to content

Commit 94b7889

Browse files
committed
Time: 3 ms (86.19%), Space: 46.2 MB (13.76%) - LeetHub
1 parent 83469ff commit 94b7889

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

1-two-sum/1-two-sum.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int[] twoSum(int[] nums, int target) {
3+
Map<Integer,Integer> map = new HashMap<Integer,Integer>();
4+
5+
for(int i=0; i< nums.length; i++){
6+
int complement = target - nums[i];
7+
if(map.containsKey(complement)) {
8+
return new int[] { map.get(complement), i};
9+
}else{
10+
map.put(nums[i],i);
11+
}
12+
}
13+
return null;
14+
}
15+
}

0 commit comments

Comments
 (0)