leetcode

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

commit 9e15dcefeca18cc159971a77fcfa0cf6fbe824df
parent 5537293c21d308449cf9c7ced6f6c8d04059270e
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 22 Feb 2023 23:59:34 +0100

Daily Problem

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

diff --git a/Problems/1011 b/Problems/1011 @@ -0,0 +1,16 @@ +class Solution { +public: + int shipWithinDays(vector<int>& weights, int days) { + int left = 0, right = 25000000; + for (int w: weights) left = max(left, w); + while (left < right) { + int mid = (left + right) / 2, need = 1, cur = 0; + for (int i = 0; i < weights.size() && need <= days; cur += weights[i++]) + if (cur + weights[i] > mid) + cur = 0, need++; + if (need > days) left = mid + 1; + else right = mid; + } + return left; + } +}; diff --git a/README.md b/README.md @@ -344,6 +344,7 @@ for solving problems. | 0994 | Medium | [Rotting Oranges](Problems/0994.cpp) | | 0997 | Easy | [Find the Town Judge](Problems/0997.cpp) | | 1008 | Medium | [Construct Binary Search Tree from Preorder Traversal](Problems/1008.cpp) | +| 1011 | Medium | [Capacity To Ship Packages Within D Days](Problems/1011.cpp) | | 1014 | Medium | [Best Sightseeing Pair](Problems/1014.cpp) | | 1019 | Medium | [Next Greater Node In Linked List](Problems/1019.cpp) | | 1022 | Easy | [Sum of Root To Leaf Binary Numbers](Problems/1022.cpp) |