Skip to content

Latest commit

 

History

History

largest-positive-integer-that-exists-with-its-negative

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Largest positive integer that exists with its negative

Problem link

Solutions

Solution.cpp

// https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/

class Solution {
public:
 int findMaxK(vector<int>& nums) {
   unordered_set<int> s;
   for (int x : nums) s.insert(x);
   int best = -1;
   for (int x : nums)
     if (s.count(-x)) best = max(best, x);
   return best;
 }
};

Tags