2025-08-03 10:19:10 +0000 UTC
Reformat The String
Categories:
Links
Code
class Solution:
def reformat(self, s: str) -> str:
res, digits, al = [""], [], []
for char in s:
if char.isalpha():
al.append(char)
else:
digits.append(char)
while digits and al:
res.extend((digits.pop(), al.pop()))
if digits:
res.append(digits.pop())
elif al:
res[0] = al.pop()
if digits or al:
return ""
return "".join(res)