leetcode

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

commit eb9d4957d3db84259b9023b98a51cb5ce4f6a3f9
parent d877a7e0379b723cf4f39b63bf08d15a28874e34
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri,  1 Mar 2024 17:51:13 +0000

Daily Problem

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

diff --git a/Problems/2864.cpp b/Problems/2864.cpp @@ -0,0 +1,14 @@ +class Solution { + public: + string maximumOddBinaryNumber(const string &s) const { + const int n = size(s); + string res(n, '0'); + int cnt = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '1') res[cnt++] = '1'; + } + if (cnt == n) return s; + res[--cnt] = '0', res.back() = '1'; + return res; + } +}; diff --git a/README.md b/README.md @@ -1135,6 +1135,7 @@ for solving problems. | 2840 | Medium | [Check if Strings Can be Made Equal With Operations II](Problems/2840.cpp) | | 2849 | Medium | [Determine if a Cell Is Reachable at a Given Time](Problems/2849.cpp) | | 2856 | Medium | [Minimum Array Length After Pair Removals](Problems/2856.cpp) | +| 2864 | Easy | [Maximum Odd Binary Number](Problems/2864.cpp) | | 2870 | Medium | [Minimum Number of Operations to Make Array Empty](Problems/2870.cpp) | | 2895 | Medium | [Minimum Processing Time](Problems/2895.cpp) | | 2900 | Medium | [Longest Unequal Adjacent Groups Subsequence I](Problems/2900.cpp) |