:
: https://reurl.cc/lQeDQj
:
: 2441. Largest Positive Integer That Exists With Its Negative
:
: 给定一不包含0的数列,寻找最大正整数,此正整数k的-k需存在于nums
:
: 回传正整数k 如果无符合条件的正整数 回传-1
:
: Example 1:
:
: Input: nums = [-1,2,-3,3]
: Output: 3
: Explanation: 3 is the only valid k we can find in the array.
婷婷:可不可以用unordered map
其实用set也可以捏
反正只是记录而已
捏
```cpp
class Solution {
public:
int findMaxK(vector<int>& nums)
{
int res = -1;
int len = nums.size();
unordered_set<int> paper;
for(int k : nums)
{
if(paper.find(-k) != paper.end())res = max(res,abs(k));
paper.insert(k);
}
return res;
}
};
```