#2441
Largest Positive Integer That Exists With Its Negative
newbie · 230 · lc easy +17 · verified · 74.5% accepted · 1,060 likes · top 85%
Description
Given an array nums of non-zero integers with no duplicates, find the largest positive integer k in nums such that -k also appears in nums.
Return k, or -1 if no such integer exists.
Example 1:
Input: nums = [-1,2,-3,3]
Output: 3
Explanation: 3 is the only valid k we can find in the array.
Example 2:
Input: nums = [-1,10,6,7,-7,1]
Output: 7
Explanation: Both 1 and 7 have their corresponding negative values in the array. 7 has a larger value.
Example 3:
Input: nums = [-10,8,6,7,-2,-3]
Output: -1
Explanation: There is no a single valid k, we return -1.
Code
1
2
3