题解:
- 按题意模拟
- 先将英文字母转成数字
- 每转一轮数字,下一轮数字为上一轮数字的每位之和
class Solution {
public int getLucky(String s, int k) {
StringBuilder stringBuilder = new StringBuilder();
for (char c : s.toCharArray()) {
if (c >= 'a' && c <= 'z') {
int i = c - 'a' + 1;
stringBuilder.append(i);
}
}
while (k-- > 0) {
int temp = 0;
for (char c : stringBuilder.toString().toCharArray()) {
temp += c - '0';
}
stringBuilder = new StringBuilder(String.valueOf(temp));
}
return Integer.parseInt(stringBuilder.toString());
}
}
标签:各位,数字,temp,int,stringBuilder,1945,StringBuilder,字符串
From: https://www.cnblogs.com/eiffelzero/p/16986020.html