leetcode

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

commit d877a7e0379b723cf4f39b63bf08d15a28874e34
parent 33bccadc904bc2d529c516c3b68c61e3fd5fb3d1
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Thu, 29 Feb 2024 15:12:35 +0000

1 Random Problem

Diffstat:
A Problems/2952.cpp | ++++++++++++++++++
M README.md | +

2 files changed, 19 insertions(+), 0 deletions(-)


diff --git a/ Problems/2952.cpp b/ Problems/2952.cpp

@@ -0,0 +1,18 @@
class Solution {
public:
int minimumAddedCoins(vector<int> &coins, int target) const {
int res = 0, get = 0;
sort(begin(coins), end(coins));
for (int i = 0; i < size(coins) && get < target; i++) {
while (get + 1 < coins[i])
get += get + 1, res++;
get += coins[i];
}
while (get < target)
get += get + 1, res++;
return res;
}
};

diff --git a/ README.md b/ README.md

@@ -1141,6 +1141,7 @@ for solving problems. | 2914 | Medium | [Minimum Number of Changes to Make Binary String Beautiful](Problems/2914.cpp) | | 2924 | Medium | [Find Champion II](Problems/2924.cpp) | | 2947 | Medium | [Count Beautiful Substrings I](Problems/2947.cpp) |
| 2952 | Medium | [Minimum Number of Coins to be Added](Problems/2952.cpp) |
| 2966 | Medium | [Divide Array Into Arrays With Max Difference](Problems/2966.cpp) | | 2971 | Medium | [Find Polygon With the Largest Perimeter](Problems/2971.cpp) | | 2997 | Medium | [Minimum Number of Operations to Make Array XOR Equal to K](Problems/2997.cpp) |