File tree Expand file tree Collapse file tree 2 files changed +4
-5
lines changed Expand file tree Collapse file tree 2 files changed +4
-5
lines changed Original file line number Diff line number Diff line change 3
3
class Solution {
4
4
public boolean containsDuplicate (int [] nums ) {
5
5
Set <Integer > set = new HashSet <>();
6
- for (int num : nums ) {
7
- if (!set .add (num )) return true ;
6
+ for (int num : nums ) {
7
+ if (!set .add (num )) return true ;
8
8
}
9
9
return false ;
10
10
}
Original file line number Diff line number Diff line change 2
2
import java .util .Map ;
3
3
4
4
/**
5
- 본래 brute force로 이중 for문으로 풀었다가 map으로 최적화.
5
+ * 본래 brute force로 이중 for문으로 풀었다가 map으로 최적화.
6
6
*/
7
7
class Solution {
8
8
/**
@@ -18,15 +18,14 @@ class Solution {
18
18
// }
19
19
// return new int[2];
20
20
// }
21
-
22
21
public int [] twoSum (int [] nums , int target ) {
23
22
Map <Integer , Integer > numberMap = new HashMap <>();
24
23
for (int i = 0 ; i < nums .length ; i ++) {
25
24
int required = target - nums [i ];
26
25
Integer index = numberMap .get (required );
27
26
28
27
if (index != null ) {
29
- return new int [] { index , i };
28
+ return new int []{ index , i };
30
29
}
31
30
numberMap .put (nums [i ], i );
32
31
}
You can’t perform that action at this time.
0 commit comments