Leetcode 953 Solution
This article provides solution to leetcode question 953 (reverse-only-letters)
Access this page by simply typing in "lcs 953" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/reverse-only-letters
Solution
class Solution:
def reverseOnlyLetters(self, S: str) -> str:
letters = [c for c in S if c.isalpha()]
ans = []
for ch in S:
if ch.isalpha():
ans.append(letters.pop())
else:
ans.append(ch)
return "".join(ans)