leetcode

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

commit fe72b05c2d9a181e2d96cd5cacd45e0a5b8a0b99
parent b81cb4910ddbc001f0a49fd43d46d1f196c47a21
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sun, 16 Jun 2024 21:05:31 +0200

Daily Problem

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

diff --git a/Problems/0330.cpp b/Problems/0330.cpp @@ -0,0 +1,16 @@ +class Solution { + public: + int minPatches(const vector<int> &nums, const int n) const { + long long sum = 0; + int res = 0, i = 0; + + while (sum < n) { + if (i < size(nums) && nums[i] <= sum + 1) + sum += nums[i++]; + else + sum += sum + 1, res++; + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -275,6 +275,7 @@ for solving problems. | 0322 | Medium | [Coin Change](Problems/0322.cpp) | | 0326 | Easy | [Power of Three](Problems/0326.cpp) | | 0328 | Medium | [Odd Even Linked List](Problems/0328.cpp) | +| 0330 | Hard | [Patching Array](Problems/0330.cpp) | | 0332 | Hard | [Reconstruct Itinerary](Problems/0332.cpp) | | 0334 | Medium | [Increasing Triplet Subsequence](Problems/0334.cpp) | | 0337 | Medium | [House Robber III](Problems/0337.cpp) |