Skip to content

Commit e4fc0e9

Browse files
Create 1816. Truncate Sentence.py
1 parent 065c729 commit e4fc0e9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def truncateSentence(self, s: str, k: int) -> str:
3+
truncated_string = ''
4+
count = 0
5+
for char in s:
6+
if char == ' ':
7+
count += 1
8+
if count == k:
9+
break
10+
truncated_string += char
11+
return truncated_string

0 commit comments

Comments
 (0)