You are given a string s consisting of lowercase English letters, and an integer k.
First, convert s into an integer by replacing each letter with its position in the alphabet (i.e., replace 'a' with 1, 'b' with 2, ..., 'z' with 26). Then, transform the integer by replacing it with the sum of its digits. Repeat the transform operation k times in total.
For example, if s = "zbax" and k = 2, then the resulting integer would be 8 by the following operations:
Convert: "zbax" ➝ "(26)(2)(1)(24)" ➝ "262124" ➝ 262124
Transform #1: 262124 ➝ 2 + 6 + 2 + 1 + 2 + 4 ➝ 17
Transform #2: 17 ➝ 1 + 7 ➝ 8
Return the resulting integer after performing the operations described above.
Example 1:
Input: s = "iiii", k = 1
Output: 36
Explanation: The operations are as follows:
Input: s = "leetcode", k = 2
Output: 6
Explanation: The operations are as follows:
Input: s = "zbax", k = 2
Output: 8
Constraints:
1 <= s.length <= 100
1 <= k <= 10
s consists of lowercase English letters.
// 변경 후 문자열 숫자의 함
// 소문자로 구성된 문자열 s를
class Solution {
public int getLucky(String s, int k) {
int lucky = 0;
return lucky;
}
private int convert(String s) {
int convert = 0;
for (char index: s.toCharArray()) {
convert += getNumber(index);
}
}
private void getNumber(char index) {
}
릿코드를 못 풀었으니 TIL을 기록할게요
private int transformFirst(int convert) {
int transformFirst = 0;
convert
}
private int transformSecond(int transformFirst) {
return transformFirst % 10 + (transformFirst / n * 10)
}
}
배운점
이유
개선 포인트