K and -K
Given a list of integers nums, return the largest integer k where k and -k both exist in nums (they can be the same integer). If there’s no such integer, return -1.
Constraints
n ≤ 100,000wherenis the length ofnums
https://binarysearch.com/problems/K-and-K
Examples
Example 1
Input
- nums =
[-4, 1, 8, -5, 4, -8]
Output
- answer =
8
Example 2
Input
- nums =
[5, 6, 1, -2]
Output
- answer =
-1
Example 3
Input
- nums =
[1, 2, 0, 3, 4]
Output
- answer =
0
Leave a comment