java.lang.Object
g2701_2800.s2733_neither_minimum_nor_maximum.Solution

public class Solution extends Object
2733 - Neither Minimum nor Maximum.<p>Easy</p> <p>Given an integer array <code>nums</code> containing <strong>distinct</strong> <strong>positive</strong> integers, find and return <strong>any</strong> number from the array that is neither the <strong>minimum</strong> nor the <strong>maximum</strong> value in the array, or **<code>-1</code> ** if there is no such number.</p> <p>Return <em>the selected integer.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [3,2,1,4]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> In this example, the minimum value is 1 and the maximum value is 4. Therefore, either 2 or 3 can be valid answers.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,2]</p> <p><strong>Output:</strong> -1</p> <p><strong>Explanation:</strong> Since there is no number in nums that is neither the maximum nor the minimum, we cannot select a number that satisfies the given condition. Therefore, there is no answer.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [2,1,3]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> Since 2 is neither the maximum nor the minimum value in nums, it is the only valid answer.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 100</code></li> <li><code>1 <= nums[i] <= 100</code></li> <li>All values in <code>nums</code> are distinct</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findNonMinOrMax

      public int findNonMinOrMax(int[] nums)