leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | e858793a144cf47b2530fc4148ddebab400d1af8 |
parent | 55f47e6e64aaae6e8776d3d57dddce82d6c05586 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Thu, 14 Mar 2024 14:52:00 +0000 |
1 Random Problem
Diffstat:A | Problems/1404.cpp | | | +++++++++++++ |
M | README.md | | | + |
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/Problems/1404.cpp b/Problems/1404.cpp
@@ -0,0 +1,13 @@
class Solution {
public:
int numSteps(const string &s) const {
int res = 0, add = 0;
for (int i = size(s) - 1; i > 0; i--) {
if (s[i] - '0' + add == 1) add = 1, res++;
res++;
}
return res + add;
}
};
diff --git a/README.md b/README.md
@@ -746,6 +746,7 @@ for solving problems.
| 1396 | Medium | [Design Underground System](Problems/1396.cpp) |
| 1400 | Medium | [Construct K Palindrome Strings](Problems/1400.cpp) |
| 1402 | Hard | [Reducing Dishes](Problems/1402.cpp) |
| 1404 | Medium | [Number of Steps to Reduce a Number in Binary Representation to One](Problems/1404.cpp) |
| 1405 | Medium | [Longest Happy String](Problems/1405.cpp) |
| 1406 | Hard | [Stone Game III](Problems/1406.cpp) |
| 1407 | Easy | [Top Travellers](Problems/1407.cpp) |