commit c7a3c05c4531c60d82027c7f995e5651c93d86f8 parent 5bf89e793b9e662d2e6595c03219873424fd5fb4 Author: Dimitrije Dobrota <mail@dimitrijedobrota.com> Date: Tue, 3 Dec 2024 12:38:30 +0100 1 Random Problem Diffstat:
A | Problems/0738.cpp | | | 19 | +++++++++++++++++++ |
M | README.md | | | 1 | + |
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/Problems/0738.cpp b/Problems/0738.cpp @@ -0,0 +1,19 @@ +class Solution { + public: + int monotoneIncreasingDigits(int n) const { + string num = to_string(n); + const int m = size(num); + int stop = m - 1; + + for (int i = m - 1; i > 0; i--) { + if (num[i] >= num[i - 1]) continue; + stop = i - 1; + num[i - 1]--; + } + + for (int i = stop + 1; i < m; i++) + num[i] = '9'; + + return stoi(num); + } +}; diff --git a/README.md b/README.md @@ -559,6 +559,7 @@ reference and a base for solving problems. | 0731 | Medium | [My Calendar II](Problems/0731.cpp) | | 0733 | Easy | [Flood Fill](Problems/0733.cpp) | | 0735 | Medium | [Asteroid Collision](Problems/0735.cpp) | +| 0738 | Medium | [Monotone Increasing Digits](Problems/0738.cpp) | | 0739 | Medium | [Daily Temperatures](Problems/0739.cpp) | | 0740 | Medium | [Delete and Earn](Problems/0740.cpp) | | 0743 | Medium | [Network Delay Time](Problems/0743.cpp) |