Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor FindMax class and improve findMax method
Refactored the FindMax class by simplifying the constructor and optimizing the findMax method's checks and loop.
  • Loading branch information
MuhammadMuneebMubashar authored Feb 12, 2026
commit 67f743a1b9d2de1deb3ffcd245efd8b9e40cab98
18 changes: 5 additions & 13 deletions src/main/java/com/thealgorithms/maths/FindMax.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
package com.thealgorithms.maths;

public final class FindMax {
private FindMax() {
}
private FindMax() {}

/**
* @brief finds the maximum value stored in the input array
*
* @param array the input array
* @exception IllegalArgumentException input array is empty
* @return the maximum value stored in the input array
*/
public static int findMax(final int[] array) {
int n = array.length;
if (n == 0) {
if (array.length == 0) {
throw new IllegalArgumentException("Array must be non-empty.");
}

int max = array[0];
for (int i = 1; i < n; i++) {
max = Math.max(array[i] , max);
for (int i = 1; i < array.length; i++) {
max = Math.max(array[i], max);
}
return max;
}
Expand Down
Loading