This commit is contained in:
parent
6151b8b474
commit
8a6b22d753
1 changed files with 19 additions and 0 deletions
19
easy/divide_a_string_into_groups_of_size_k.py
Normal file
19
easy/divide_a_string_into_groups_of_size_k.py
Normal file
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue