How to find biggest number in int array

How to find biggest number in int array

·

1 min read

Example

[7,1,5,3,6] -> 7

JAVA code

  • Time Complexity: O(n)
  • Space Complexity: O(1)
    public static int getMaxFromArray(int[] input) {
        int max = Integer.MIN_VALUE;
        for (int temp : input) {
            if (max < temp) {
                max = temp;
            }
        }
        return max;
    }