Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 001a97a

Browse files
Sum of Digits of String After Convert
1 parent be7ec05 commit 001a97a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Link: https://leetcode.com/problems/sum-of-digits-of-string-after-convert/
2+
Language: C#
3+
4+
5+
6+
7+
8+
9+
public class Solution {
10+
public int GetLucky(string s, int k)
11+
{
12+
int sum = 0;
13+
string temp = "";
14+
15+
for (int i = 0; i < s.Length; i++)
16+
{
17+
temp += s[i] - 'a' + 1;
18+
}
19+
20+
while (k >= 1)
21+
{
22+
sum = 0;
23+
24+
for (int i = 0; i < temp.Length; i++)
25+
{
26+
sum += temp[i] - '0';
27+
}
28+
29+
temp = sum.ToString();
30+
k--;
31+
}
32+
33+
return sum;
34+
}
35+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /