File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 4
4
class Solution {
5
5
public boolean containsDuplicate (int [] nums ) {
6
6
Set <Integer > set = new HashSet ();
7
+
7
8
for (int n : nums ){
8
9
if (set .contains (n )){
9
10
return true ;
10
11
}
11
12
set .add (n );
12
13
}
14
+
13
15
return false ;
14
16
}
15
17
}
Original file line number Diff line number Diff line change 4
4
class Solution {
5
5
public int [] twoSum (int [] nums , int target ) {
6
6
Map <Integer , Integer > map = new HashMap <>();
7
- for (int i = 0 ; i < nums .length ; i ++){
7
+
8
+ for (int i = 0 ; i < nums .length ; i ++) {
8
9
map .put (nums [i ], i );
9
10
}
10
11
11
- for (int i = 0 ; i < nums .length ; i ++){
12
- if (map .containsKey (target - nums [i ])
13
- && map .get (target - nums [i ]) != i ){
12
+ for (int i = 0 ; i < nums .length ; i ++) {
13
+ if (map .containsKey (target - nums [i ]) && map .get (target - nums [i ]) != i ) {
14
14
int j = map .get (target - nums [i ]);
15
15
return new int []{i , j };
16
16
}
17
17
}
18
+
18
19
return null ;
19
20
}
20
21
}
You can’t perform that action at this time.
0 commit comments