Skip to content

Commit 95e992a

Browse files
committed
fix: two sum, remove map.get(pair) condition
1 parent ddd020b commit 95e992a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

two-sum/YuuuuuuYu.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* Runtime: 3ms
2+
* Runtime: 2ms
33
* Time Complexity: O(n)
44
*
5-
* Memory: 46.97MB
5+
* Memory: 47.41MB
66
* Space Complexity: O(n)
77
*
88
* Approach: HashMap을 사용하여 짝을 이루는 값(pair) 검사
@@ -14,7 +14,7 @@ public int[] twoSum(int[] nums, int target) {
1414
Map <Integer, Integer> map = new HashMap<>();
1515
for (int i=0; i<nums.length; i++) {
1616
int pair = target-nums[i];
17-
if (map.containsKey(pair) && map.get(pair) != i) {
17+
if (map.containsKey(pair)) {
1818
return new int[]{i, map.get(pair)};
1919
}
2020
map.put(nums[i], i);

0 commit comments

Comments
 (0)