Skip to content

Commit 1274140

Browse files
authored
Update PigeonholeSort.java
1 parent 9fe55c8 commit 1274140

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/main/java/src/main/java/com/sorts/PigeonholeSort.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,12 @@ public class PigeonholeSort {
1717
public Integer[] sort(Integer[] arr) {
1818

1919
// Find maximum and minimum elements in array
20-
int min = arr[0];
21-
int max = arr[0];
20+
int min = Integer.MAX_VALUE;
21+
int max = Integer.MIN_VALUE;
2222

2323
for (Integer integer : arr) {
24-
25-
// For minimum value
26-
if (min > integer) {
27-
min = integer;
28-
}
29-
30-
// For maximum value
31-
if (max < integer) {
32-
max = integer;
33-
}
24+
min = Math.min(min, integer);
25+
max = Math.max(max, integer);
3426
}
3527

3628
// Range

0 commit comments

Comments
 (0)