1
class Solution {
2
public:
3
string truncateSentence(string s, int k) {
4
int n = s.size();
5

6
string ans;
7
int cnt = 0;
8
for (int i = 0; i < n; i++) {
9
if (s[i] == ' ') {
10
cnt++;
11
}
12

13
if (k == cnt) {
14
return ans;
15
}
16

17
ans += s[i];
18
}
19

20
return ans;
21
}
22
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0