Sum of Digits of String After Convert
给一个string表示数字, 求n次数字位求和后的结果.
class Solution {
public int getLucky(String s, int k) {
StringBuilder sb = new StringBuilder();
for(char c : s.toCharArray())
sb.append((c - 'a') + 1);
s = sb.toString();
while(k != 0)
{
int sum = 0;
for(char c : s.toCharArray())
{
sum += c - '0';
}
s = sum + "";
k--;
}
return Integer.valueOf(s);
}
}