From bf777fff8f075cccff32223cd2f5c085adb5b09e Mon Sep 17 00:00:00 2001 From: Lukas <142339568+lukasb1b@users.noreply.github.com> Date: Tue, 26 Sep 2023 17:31:16 +0200 Subject: [PATCH] Remove array len + Math.min (#4405) --- .../java/com/thealgorithms/maths/FindMinRecursion.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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); } }