1945. Sum of Digits of String After Convert
You are given a string
s
consisting of lowercase English letters, and an integerk
.First, convert
s
into an integer by replacing each letter with its position in the alphabet (i.e., replace'a'
with1
,'b'
with2
, …,'z'
with26
). Then, transform the integer by replacing it with the sum of its digits. Repeat the transform operationk
times in total.For example, if
s = "zbax"
andk = 2
, then the resulting integer would be8
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.
1 | class Solution { |