We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f2d6f3a + b416d1f commit 6c0fe15Copy full SHA for 6c0fe15
1945. Sum of Digits of String After Convert
@@ -0,0 +1,37 @@
1
+class Solution {
2
+public:
3
+ int transform(int num){
4
+
5
+ int sum = 0;
6
7
+ while(num>0){
8
9
+ int digit = num % 10;
10
+ sum += digit;
11
+ num /= 10;
12
13
+ }
14
15
+ return sum;
16
17
18
+ int getLucky(string s, int k) {
19
20
+ string str;
21
22
+ for (auto& c : s) {
23
+ str += to_string((c - 'a') + 1);
24
25
26
27
+ for (auto& digits : str) {
28
+ sum += digits - '0';
29
30
31
+ for(int i=1;i<k;i++){
32
+ sum = transform(sum);
33
34
35
36
37
+};
0 commit comments