leetcode

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

commit b6ac96e045f08c6ef289426cee2f6139d63d9e5b
parent ee50f61f2a4975426b500be88ae4aff74455bd34
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri,  3 Mar 2023 13:14:31 +0100

Random Problem

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

diff --git a/Problems/2243.cpp b/Problems/2243.cpp @@ -0,0 +1,15 @@ +class Solution { +public: + string digitSum(string s, int k) { + while (s.size() > k) { + string tmp = ""; + for (int i = 0; i < s.size();) { + int sum = 0; + for (int j = 0; j < k && i < s.size(); i++, j++) sum += s[i] - '0'; + tmp += to_string(sum); + } + s = tmp; + } + return s; + } +}; diff --git a/README.md b/README.md @@ -446,6 +446,7 @@ for solving problems. | 2192 | Medium | [All Ancestors of a Node in a Directed Acyclic Graph](Problems/2192.cpp) | | 2235 | Easy | [Add Two Integers](Problems/2235.cpp) | | 2236 | Easy | [Root Equals Sum of Children](Problems/2236.cpp) | +| 2243 | Easy | [Calculate Digit Sum of a String](Problems/2243.cpp) | | 2244 | Medium | [Minimum Rounds to Complete All Tasks](Problems/2244.cpp) | | 2246 | Hard | [Longest Path With Different Adjacent Characters](Problems/2246.cpp) | | 2265 | Medium | [Count Nodes Equal to Average of Subtree](Problems/2265.cpp) |