HTMLify
LeetCode - Reverse Only Letters - Python
Views: 493 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 | class Solution: def reverseOnlyLetters(self, s: str) -> str: s = list(s) chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM" letters = [] for c in s: if c in chars: letters.append(c) for i in range(len(s)): if s[i] in chars: s[i] = letters.pop() return "".join(s) |