0
点赞
收藏
分享

微信扫一扫

LeetCode题解(1844):将所有数字用字符替换(Python)


题目:​​原题链接​​(简单)

标签:字符串

解法

时间复杂度

空间复杂度

执行用时

Ans 1 (Python)

40ms (61.30%)

Ans 2 (Python)

Ans 3 (Python)

解法一:

class Solution:
def replaceDigits(self, s: str) -> str:
lst = list(s)
size = len(lst)

for i in range(1, size, 2):
c, x = lst[i - 1], int(lst[i])
lst[i] = chr(((ord(c) - 97) + x) % 26 + 97)

return "".join(lst)


举报

相关推荐

0 条评论