leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 50c0e709dc9371f0e221eb3073f128006a557b49 |
parent | 0c75ff87e2e5161d1b87351dbed2148f5100771c |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Tue, 3 Sep 2024 19:45:41 +0200 |
Daily Problem
Diffstat:A | Problems/1945.cpp | | | ++++++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/Problems/1945.cpp b/Problems/1945.cpp
@@ -0,0 +1,24 @@
class Solution {
static int sum(int n) {
int res = 0;
while (n > 0) {
res += n % 10;
n /= 10;
}
return res;
}
public:
int getLucky(const string &s, int k) const {
int res = 0;
for (const char c : s)
res += sum(c - '`');
for (int i = 1; i < k; i++)
res = sum(res);
return res;
}
};
diff --git a/README.md b/README.md
@@ -1043,6 +1043,7 @@ for solving problems.
| 1934 | Medium | [Confirmation Rate](Problems/1934.cpp) |
| 1937 | Medium | [Maximum Number of Points with Cost](Problems/1937.cpp) |
| 1943 | Medium | [Describe the Painting](Problems/1943.cpp) |
| 1945 | Easy | [Sum of Digits of String After Convert](Problems/1945.cpp) |
| 1947 | Medium | [Maximum Compatibility Score Sum](Problems/1947.cpp) |
| 1954 | Medium | [Minimum Garden Perimeter to Collect Enough Apples](Problems/1954.cpp) |
| 1962 | Medium | [Remove Stones to Minimize the Total](Problems/1962.cpp) |