1816. Truncate Sentence Updated: 2024-03-12 1 min read Algorithms , LeetCode On This PageLeetCode problem 1816class 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