1417. Reformat The String
On This Page
class Solution:
def reformat(self, s: str) -> str:
a = [c for c in s if c.islower()]
b = [c for c in s if c.isdigit()]
if abs(len(a) - len(b)) > 1:
return ''
if len(a) < len(b):
a, b = b, a
res = []
for x, y in zip(a, b):
res.append(x + y)
if len(a) > len(b):
res.append(a[-1])
return ''.join(res)