Class Solution
java.lang.Object
g2401_2500.s2441_largest_positive_integer_that_exists_with_its_negative.Solution
2441 - Largest Positive Integer That Exists With Its Negative.<p>Easy</p>
<p>Given an integer array <code>nums</code> that <strong>does not contain</strong> any zeros, find <strong>the largest positive</strong> integer <code>k</code> such that <code>-k</code> also exists in the array.</p>
<p>Return <em>the positive integer</em> <code>k</code>. If there is no such integer, return <code>-1</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [-1,2,-3,3]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> 3 is the only valid k we can find in the array.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [-1,10,6,7,-7,1]</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Explanation:</strong> Both 1 and 7 have their corresponding negative values in the array. 7 has a larger value.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [-10,8,6,7,-2,-3]</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> There is no a single valid k, we return -1.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 1000</code></li>
<li><code>-1000 <= nums[i] <= 1000</code></li>
<li><code>nums[i] != 0</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findMaxK
public int findMaxK(int[] nums)
-