Skip to content

Commit 26b2bc5

Browse files
committed
commit
1 parent 09ba3f8 commit 26b2bc5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

1. Two Sum.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
class Solution {
22
public int[] twoSum(int[] nums, int target) {
3+
// Create hash map
34
Map<Integer, Integer> map = new HashMap();
45

6+
// Itterate through array element
57
for (int idx = 0; idx < nums.length; idx++) {
8+
// Complement of target and current element
69
int complement = target - nums[idx];
710

11+
// Check if complement exists in map
812
if (map.containsKey(complement)) {
9-
return new int[]{map.get(complement), idx};
13+
// Return results
14+
return new int[] { map.get(complement), idx };
1015
}
11-
16+
17+
// Put element into map
1218
map.put(nums[idx], idx);
1319
}
1420

0 commit comments

Comments
 (0)