We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 09ba3f8 commit 26b2bc5Copy full SHA for 26b2bc5
1. Two Sum.java
@@ -1,14 +1,20 @@
1
class Solution {
2
public int[] twoSum(int[] nums, int target) {
3
+ // Create hash map
4
Map<Integer, Integer> map = new HashMap();
5
6
+ // Itterate through array element
7
for (int idx = 0; idx < nums.length; idx++) {
8
+ // Complement of target and current element
9
int complement = target - nums[idx];
10
11
+ // Check if complement exists in map
12
if (map.containsKey(complement)) {
- return new int[]{map.get(complement), idx};
13
+ // Return results
14
+ return new int[] { map.get(complement), idx };
15
}
-
16
+
17
+ // Put element into map
18
map.put(nums[idx], idx);
19
20
0 commit comments