Re: [閒聊] 每日leetcode
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
```
--
http://i.imgur.com/OLvBn3b.jpg

--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.146 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1725374111.A.0F5.html
推
09/03 22:36,
1年前
, 1F
09/03 22:36, 1F
推
09/03 22:44,
1年前
, 2F
09/03 22:44, 2F
討論串 (同標題文章)
完整討論串 (本文為第 802 之 1548 篇):