From 1274140ea369fcf1a806bec99a495cb93220bf4a Mon Sep 17 00:00:00 2001 From: Libin Yang Date: Fri, 4 Jan 2019 20:38:49 +0800 Subject: [PATCH] Update PigeonholeSort.java --- .../src/main/java/com/sorts/PigeonholeSort.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/src/main/java/com/sorts/PigeonholeSort.java b/src/main/java/src/main/java/com/sorts/PigeonholeSort.java index 6b77050b..1f8b498b 100644 --- a/src/main/java/src/main/java/com/sorts/PigeonholeSort.java +++ b/src/main/java/src/main/java/com/sorts/PigeonholeSort.java @@ -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