Re: [闲聊] 每日leetcode

楼主: dont   2024-09-03 22:35:08
1945. Sum of Digits of String After Convert
## 思路
第1轮把字符都转成数字再加总digit
第2~k轮就digit加总
## Code
```python
class Solution:
def getLucky(self, s: str, k: int) -> int:
res = 0
for ch in s:
pos = ord(ch) - ord('a') + 1
res += pos // 10 + pos % 10
for _ in range(1, k):
curr = 0
while res:
res, digit = divmod(res, 10)
curr += digit
res = curr
return res
```
作者: sustainer123 (caster)   2024-09-03 22:36:00
大师
作者: DJYOMIYAHINA (通通打死)   2024-09-03 22:44:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com