leetcode

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

commit 6aab8e1022ac6062449a52da487b0a5bcaa8a84a
parent 6867f0bdda4aa21c7e4cea5c9e9e1ccae5f7da14
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri, 27 Sep 2024 17:08:58 +0200

Daily Problem

Diffstat:
AProblems/0731.cpp | 23+++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/Problems/0731.cpp b/Problems/0731.cpp @@ -0,0 +1,23 @@ +class MyCalendarTwo { + using interval = pair<int, int>; + vector<interval> sgl, dbl; + + static bool isOverlap(int s1, int e1, int s2, int e2) { return max(s1, s2) < min(e1, e2); } + + static interval overlap(int s1, int e1, int s2, int e2) { return {max(s1, s2), min(e1, e2)}; } + + public: + bool book(int start, int end) { + for (const auto [s, e] : dbl) { + if (isOverlap(start, end, s, e)) return false; + } + + for (const auto [s, e] : sgl) { + if (!isOverlap(start, end, s, e)) continue; + dbl.push_back(overlap(start, end, s, e)); + } + + sgl.emplace_back(start, end); + return true; + } +}; diff --git a/README.md b/README.md @@ -488,6 +488,7 @@ for solving problems. | 0725 | Medium | [Split Linked List in Parts](Problems/0725.cpp) | | 0726 | Hard | [Number of Atoms](Problems/0726.cpp) | | 0729 | Medium | [My Calendar I](Problems/0729.cpp) | +| 0731 | Medium | [My Calendar II](Problems/0731.cpp) | | 0733 | Easy | [Flood Fill](Problems/0733.cpp) | | 0735 | Medium | [Asteroid Collision](Problems/0735.cpp) | | 0739 | Medium | [Daily Temperatures](Problems/0739.cpp) |