Sentence Reversal
Given a list of strings sentence where each sentence[i] is a string with single character, reverse the order of the words in the sentence.
You may assume there’s no extraneous spaces in the sentence. Can you do modify sentence in-place and solve in \(\mathcal{O}(1)\) space?
Constraints
n ≤ 10,000wherenis the length ofsentence.
https://binarysearch.com/problems/Sentence-Reversal
Examples
Example 1
Input
- sentence =
['h', 'i', ' ', 'w', 'o', 'r', 'l', 'd']
Output
- answer =
['w', 'o', 'r', 'l', 'd', ' ', 'h', 'i']
Leave a comment