leetcode

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

commit a1f043c44f6e2870178ff62025f2c3dce5a09932
parent 484afbc6e24acf0ca7e8a058b666a966afb020aa
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon, 13 Nov 2023 20:10:42 +0000

Random Problem

Diffstat:
AProblems/0900.cpp | 15+++++++++++++++
MREADME.md | 1+
2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/Problems/0900.cpp b/Problems/0900.cpp @@ -0,0 +1,15 @@ +class RLEIterator { + vector<int> &vec; + int idx = 0; + + public: + RLEIterator(vector<int> &encoding) : vec(encoding) {} + + int next(int n) { + while (idx < vec.size() && n > vec[idx]) + n -= vec[idx], idx += 2; + if (idx >= vec.size()) return -1; + vec[idx] -= n; + return vec[idx + 1]; + } +}; diff --git a/README.md b/README.md @@ -451,6 +451,7 @@ for solving problems. | 0894 | Medium | [All Possible Full Binary Trees](Problems/0894.cpp) | | 0896 | Easy | [Monotonic Array](Problems/0896.cpp) | | 0897 | Easy | [Increasing Order Search Tree](Problems/0897.cpp) | +| 0900 | Medium | [RLE Iterator](Problems/0900.cpp) | | 0901 | Medium | [Online Stock Span](Problems/0901.cpp) | | 0904 | Medium | [Fruit Into Baskets](Problems/0904.cpp) | | 0905 | Easy | [Sort Array By Parity](Problems/0905.cpp) |