leetcode

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

commit b7c7c860e41c8b83baead4883433a1d729d8738b
parent 7315df8a528f60b18edc41f7163c05d4f4b7800a
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat, 20 Apr 2024 10:22:02 +0200

1 Random Problem

Diffstat:
AProblems/0436.cpp | 17+++++++++++++++++
MREADME.md | 1+
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/Problems/0436.cpp b/Problems/0436.cpp @@ -0,0 +1,17 @@ +class Solution { + public: + vector<int> findRightInterval(const vector<vector<int>> &intervals) const { + const int n = size(intervals); + vector<int> res(n); + map<int, int> mp; + + for (int i = 0; i < n; i++) + mp[intervals[i][0]] = i; + for (int i = 0; i < n; i++) { + const auto it = mp.lower_bound(intervals[i][1]); + res[i] = it != mp.end() ? it->second : -1; + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -325,6 +325,7 @@ for solving problems. | 0430 | Medium | [Flatten a Multilevel Doubly Linked list](Problems/0430.cpp) | | 0433 | Medium | [Minimum Genetic Mutation](Problems/0433.cpp) | | 0435 | Medium | [Non-overlapping Intervals](Problems/0435.cpp) | +| 0436 | Medium | [Find Right Interval](Problems/0436.cpp) | | 0437 | Medium | [Path Sum III](Problems/0437.cpp) | | 0438 | Medium | [Find All Anagrams in a String](Problems/0438.cpp) | | 0442 | Medium | [Find All Duplicates in an Array](Problems/0442.cpp) |