1816. Truncate Sentence

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

Содержание

LeetCode problem 1816

class Solution:
    def truncateSentence(self, s: str, k: int) -> str:
        for i, c in enumerate(s):
            k -= c == ' '
            if k == 0:
                return s[:i]
        return s