BudiBadu Logo

Find Smallest

Array Easy 0 views
Like25

The objective is to isolate the minimum numerical magnitude from the collection of integers provided in the nums array. This involves determining the lower bound of the dataset by identifying the singular value that is less than or equal to all other elements.

The final output must be the absolute smallest integer found, accounting for negative ranges and varying list sizes. This data point serves as the definitive bottom-most threshold for the numerical range within the sample.

Example 1:

Input: nums = [10, 5, 8, 3, 12]
Output: 3

Example 2:

Input: nums = [0, -1, -5, 2]
Output: -5

Example 3:

Input: nums = [7]
Output: 7

Algorithm Flow

Recommendation Algorithm Flow for Find Smallest - Budibadu
Recommendation Algorithm Flow for Find Smallest - Budibadu

Best Answers

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