Leetcode in Java && Oracle
421 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-10-16_00-24-46.png
39.4 KB
#N1816 Truncate Sentence
problem link=>https://leetcode.com/problems/truncate-sentence/

#solution
class Solution {
public String truncateSentence(String s, int k) {
s=s+" ";
String res="";
int start=0;
for(int i=0; i<s.length(); i++){
if(s.charAt(i)==' '&&k>0){
res+=s.substring(start, i);
start=i;
k--;
}
}

return res;
}
}