leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 59716e13b8063037239c3dba8e7fa22ae5104c9e
parent 2d891afa5660689c6a714a6e2fd84f359a8a947f
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Tue, 25 Apr 2023 11:30:34 +0200

Daily Problem

Diffstat:
AProblems/2336.cpp | 19+++++++++++++++++++
MREADME.md | 1+
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/Problems/2336.cpp b/Problems/2336.cpp @@ -0,0 +1,19 @@ +class SmallestInfiniteSet { + int count = 1; + set<int> st; + +public: + int popSmallest() { + if (!st.empty()) { + int elem = *st.begin(); + st.erase(st.begin()); + return elem; + } + return count++; + } + + void addBack(int num) { + if (num >= count) return; + st.insert(num); + } +}; diff --git a/README.md b/README.md @@ -504,6 +504,7 @@ for solving problems. | 2316 | Medium | [Count Unreachable Pairs of Nodes in an Undirected Graph](Problems/2316.cpp) | | 2326 | Medium | [Spiral Matrix IV](Problems/2326.cpp) | | 2331 | Easy | [Evaluate Boolean Binary Tree](Problems/2331.cpp) | +| 2336 | Medium | [Smallest Number in Infinite Set](Problems/2336.cpp) | | 2343 | Medium | [Query Kth Smallest Trimmed Number](Problems/2343.cpp) | | 2348 | Medium | [Number of Zero-Filled Subarrays](Problems/2348.cpp) | | 2359 | Medium | [Find Closest Node to Given Two Nodes](Problems/2359.cpp) |