File tree 4 files changed +9
-25
lines changed
src/main/java/com/thealgorithms
4 files changed +9
-25
lines changed Original file line number Diff line number Diff line change 68
68
<Match >
69
69
<Bug pattern =" IM_BAD_CHECK_FOR_ODD" />
70
70
</Match >
71
- <Match >
72
- <Bug pattern =" WMI_WRONG_MAP_ITERATOR" />
73
- </Match >
74
71
<Match >
75
72
<Bug pattern =" DM_BOXED_PRIMITIVE_FOR_PARSING" />
76
73
</Match >
Original file line number Diff line number Diff line change @@ -54,19 +54,6 @@ ArrayList<E> getAdjacents(E v) {
54
54
Set <E > getVertices () {
55
55
return adj .keySet ();
56
56
}
57
-
58
- /**
59
- * Prints the adjacency list
60
- */
61
- void printGraph () {
62
- for (E vertex : adj .keySet ()) {
63
- System .out .print (vertex + " : " );
64
- for (E adjacent : adj .get (vertex )) {
65
- System .out .print (adjacent + " " );
66
- }
67
- System .out .println ();
68
- }
69
- }
70
57
}
71
58
72
59
class TopologicalSort <E extends Comparable <E >> {
@@ -104,9 +91,9 @@ ArrayList<E> topSortOrder() {
104
91
calculateInDegree ();
105
92
Queue <E > q = new LinkedList <E >();
106
93
107
- for (E vertex : inDegree .keySet ()) {
108
- if (inDegree . get ( vertex ) == 0 ) {
109
- q .add (vertex );
94
+ for (final var entry : inDegree .entrySet ()) {
95
+ if (entry . getValue ( ) == 0 ) {
96
+ q .add (entry . getKey () );
110
97
}
111
98
}
112
99
Original file line number Diff line number Diff line change @@ -27,9 +27,9 @@ public static List<Integer> majority(int[] nums) {
27
27
}
28
28
}
29
29
List <Integer > majorityElements = new ArrayList <>();
30
- for (int key : numToCount .keySet ()) {
31
- if (numToCount . get ( key ) >= n / 2 ) {
32
- majorityElements .add (key );
30
+ for (final var entry : numToCount .entrySet ()) {
31
+ if (entry . getValue ( ) >= n / 2 ) {
32
+ majorityElements .add (entry . getKey () );
33
33
}
34
34
}
35
35
return majorityElements ;
Original file line number Diff line number Diff line change @@ -38,9 +38,9 @@ public static int[] mode(final int[] numbers) {
38
38
int max = Collections .max (count .values ());
39
39
ArrayList <Integer > modes = new ArrayList <>();
40
40
41
- for (int num : count .keySet ()) {
42
- if (count . get ( num ) == max ) {
43
- modes .add (num );
41
+ for (final var entry : count .entrySet ()) {
42
+ if (entry . getValue ( ) == max ) {
43
+ modes .add (entry . getKey () );
44
44
}
45
45
}
46
46
return modes .stream ().mapToInt (n -> n ).toArray ();
You can’t perform that action at this time.
0 commit comments