2138. Divide a String Into Groups of Size k

2022. 1. 22. 10:22Algorithm/Leetcode, Lintcode, HackerRank, etc.

    목차
반응형
class Solution:
    def divideString(self, s: str, k: int, fill: str) -> List[str]:
        n = len(s)
        res = []

        i = 0
        while i < n:
            pad = k - len(s[i:i + k])
            res += s[i:i + k] + fill*pad,
            i += k

        return res

 

반응형