Truncate Sentence LeetCode Solution - The Coding Shala
In this post, we will learn how to solve LeetCode's Truncate Sentence problem and will implement its solution in Java.
Truncate Sentence Problem
LeetCode - Truncate Sentence Java Solution
First, convert the given string to an array then take the first k words and make a string and return.
Using Java's in-built methods.
Not using split. We can count white space and return string according to that. This program is performed better than the two above.
- LeetCode - Number of Recent Calls
- LeetCode - Remove Outermost Parentheses
- LeetCode - Integer Replacement
- LeetCode - Number Complement
- LeetCode - XOR operation in an Array