BudiBadu Logo

Find Max Number

Array Easy 18 views
Like11

The objective is to identify the element representing the highest numerical magnitude within the nums array. This task requires isolating the absolute maximum value from a sequence of integers to determine the upper bound of the sample set.

The final output must be the single largest integer present in the collection, accounting for negative ranges, duplicate entries, and varying input lengths. This ensures the result accurately reflects the peak data point within the provided array.

Example 1:

Input: nums = [1, 5, 3, 9, 2]
Output: 9

Example 2:

Input: nums = [-10, -5, -20, -1]
Output: -1

Example 3:

Input: nums = [42]
Output: 42

Algorithm Flow

Recommendation Algorithm Flow for Find Max Number - Budibadu
Recommendation Algorithm Flow for Find Max Number - Budibadu

Best Answers

java
class Solution {
    public int find_max_number(int[] nums) {
        if (nums == null || nums.length == 0) return 0;
        int max = nums[0];
        for (int num : nums) {
            if (num > max) max = num;
        }
        return max;
    }
}