diff --git a/src/main/java/com/thealgorithms/maths/FindMinRecursion.java b/src/main/java/com/thealgorithms/maths/FindMinRecursion.java index 66400d23..71d7795b 100644 --- a/src/main/java/com/thealgorithms/maths/FindMinRecursion.java +++ b/src/main/java/com/thealgorithms/maths/FindMinRecursion.java @@ -21,7 +21,7 @@ public class FindMinRecursion { } assert min(array, 0, array.length - 1) == Arrays.stream(array).min().getAsInt(); - assert min(array, array.length) == Arrays.stream(array).min().getAsInt(); + assert min(array) == Arrays.stream(array).min().getAsInt(); } /** @@ -42,7 +42,7 @@ public class FindMinRecursion { int leftMin = min(array, low, mid); // get min in [low, mid] int rightMin = min(array, mid + 1, high); // get min in [mid+1, high] - return Math.min(leftMin, rightMin); + return leftMin > rightMin ? rightMin : leftMin; } /** @@ -52,7 +52,7 @@ public class FindMinRecursion { * @param len length of given array * @return min value of {@code array} */ - public static int min(int[] array, int len) { - return len == 1 ? array[0] : Math.min(min(array, len - 1), array[len - 1]); + public static int min(int[] array) { + return array.length == 1 ? array[0] : min(array, 0, array.length); } }