Class Solution
java.lang.Object
g1601_1700.s1608_special_array_with_x_elements_greater_than_or_equal_x.Solution
1608 - Special Array With X Elements Greater Than or Equal X.<p>Easy</p>
<p>You are given an array <code>nums</code> of non-negative integers. <code>nums</code> is considered <strong>special</strong> if there exists a number <code>x</code> such that there are <strong>exactly</strong> <code>x</code> numbers in <code>nums</code> that are <strong>greater than or equal to</strong> <code>x</code>.</p>
<p>Notice that <code>x</code> <strong>does not</strong> have to be an element in <code>nums</code>.</p>
<p>Return <code>x</code> <em>if the array is <strong>special</strong> , otherwise, return</em> <code>-1</code>. It can be proven that if <code>nums</code> is special, the value for <code>x</code> is <strong>unique</strong>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [3,5]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> There are 2 values (3 and 5) that are greater than or equal to 2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [0,0]</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> No numbers fit the criteria for x.</p>
<p>If x = 0, there should be 0 numbers >= x, but there are 2.</p>
<p>If x = 1, there should be 1 number >= x, but there are 0.</p>
<p>If x = 2, there should be 2 numbers >= x, but there are 0.</p>
<p>x cannot be greater since there are only 2 numbers in nums.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [0,4,3,0,4]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> There are 3 values that are greater than or equal to 3.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 100</code></li>
<li><code>0 <= nums[i] <= 1000</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
specialArray
public int specialArray(int[] nums)
-