From 8a6b22d753f6bf12b2866591eee4d9789c2875cc Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Sun, 22 Jun 2025 12:19:52 +0000 Subject: [PATCH] https://leetcode.com/problems/divide-a-string-into-groups-of-size-k --- easy/divide_a_string_into_groups_of_size_k.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 easy/divide_a_string_into_groups_of_size_k.py diff --git a/easy/divide_a_string_into_groups_of_size_k.py b/easy/divide_a_string_into_groups_of_size_k.py new file mode 100644 index 0000000..0d7b8a8 --- /dev/null +++ b/easy/divide_a_string_into_groups_of_size_k.py @@ -0,0 +1,19 @@ +# https://leetcode.com/problems/divide-a-string-into-groups-of-size-k + +from typing import List + +class Solution: + def divideString(self, s: str, k: int, fill: str) -> List[str]: + result: List[str] = [] + curr: List[str] = [] + for c in s: + if len(curr) >= k: + result.append(''.join(curr)) + curr = [] + curr.append(c) + if len(curr) > 0: + while len(curr) < k: + curr.append(fill) + result.append(''.join(curr)) + return result +