Update PigeonholeSort.java

This commit is contained in:
Libin Yang 2019-01-04 20:38:49 +08:00 committed by GitHub
parent 9fe55c82d8
commit 1274140ea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,20 +17,12 @@ public class PigeonholeSort {
public Integer[] sort(Integer[] arr) {
// Find maximum and minimum elements in array
int min = arr[0];
int max = arr[0];
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for (Integer integer : arr) {
// For minimum value
if (min > integer) {
min = integer;
}
// For maximum value
if (max < integer) {
max = integer;
}
min = Math.min(min, integer);
max = Math.max(max, integer);
}
// Range