File tree 2 files changed +9
-10
lines changed
src/main/java/by/andd3dfx
2 files changed +9
-10
lines changed Original file line number Diff line number Diff line change 1
1
package by .andd3dfx .collections ;
2
2
3
3
import java .util .HashSet ;
4
- import java .util .Set ;
5
4
6
5
/**
7
6
* <pre>
29
28
public class ContainsDuplicates {
30
29
31
30
public boolean usingSet (int [] nums ) {
32
- Set < Integer > set = new HashSet <>();
31
+ var set = new HashSet <Integer >();
33
32
for (int num : nums ) {
34
33
if (!set .add (num )) {
35
34
return true ;
@@ -40,18 +39,18 @@ public boolean usingSet(int[] nums) {
40
39
41
40
public boolean usingSortWithEarlyReturn (int [] nums ) {
42
41
for (int i = 0 ; i < nums .length ; i ++) {
43
- int min_index = i ;
42
+ int minIndex = i ;
44
43
45
44
for (int j = i + 1 ; j < nums .length ; j ++) {
46
- if (nums [j ] == nums [min_index ]) {
45
+ if (nums [j ] == nums [minIndex ]) {
47
46
return true ;
48
47
}
49
- if (nums [j ] < nums [min_index ]) {
50
- min_index = j ;
48
+ if (nums [j ] < nums [minIndex ]) {
49
+ minIndex = j ;
51
50
}
52
51
}
53
52
54
- swap (nums , i , min_index );
53
+ swap (nums , i , minIndex );
55
54
}
56
55
return false ;
57
56
}
Original file line number Diff line number Diff line change @@ -7,13 +7,13 @@ public class SelectionSort {
7
7
8
8
public static <T extends Comparable > void apply (T [] array ) {
9
9
for (int i = 0 ; i < array .length ; i ++) {
10
- int min_index = i ;
10
+ int minIndex = i ;
11
11
12
12
for (int j = i + 1 ; j < array .length ; j ++) {
13
- if (lessThan (array [j ], array [min_index ])) min_index = j ;
13
+ if (lessThan (array [j ], array [minIndex ])) minIndex = j ;
14
14
}
15
15
16
- swap (array , i , min_index );
16
+ swap (array , i , minIndex );
17
17
}
18
18
}
19
19
You can’t perform that action at this time.
0 commit comments