../ Competitive Programming
-rw-r--r--aguang763 B1 min read

Leet Code Daily 2024-05-02 - Largest Positive Integer That Exists With Its Negative

Code

c++
constexpr int kMaxNum = 1000;

class Solution {
public:
    int findMaxK(vector<int>& nums) {
        bool has_pos[kMaxNum + 1] = { false };
        bool has_neg[kMaxNum + 1] = { false };
        for (const auto& x : nums) {
            if (x >= 0) {
                has_pos[+x] = true;
            }
            if (x <= 0) {
                has_neg[-x] = true;
            }
        }
        for (int i = kMaxNum; i >= 0; i--) {
            if (has_pos[i] && has_neg[i]) {
                return i;
            }
        }
        return -1;
    }
};

COMMAND INTERFACE

↑ ↓ navigate · Enter execute · Esc exit · try “whoami”

Loading filesystem…

:help aguang.xyz

A personal website disguised as an operating system.

Ctrl / Cmd + K
Command palette + full-text search
Tab / Shift + Tab
Move between links and controls
Enter
Open a focused link or search result
↑ / ↓ in search
Navigate search results
In a directory filter
Enter/Done or ↓ focuses a result; Esc clears the filter
Esc
Clear a search or close a window