1417. Reformat The String

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1417

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)