← 返回 bytedance 的题目列表Reverse Words in a Sentence In-Place
类型:online_judge
Given a sentence, you need to reverse the order of the words in the sentence. The specific requirements are as follows:
The input is a string containing spaces; the words in the string are separated by a single space.
The reversal must be done in-place with a time complexity of O(n), where n is the length of the string.
For example, given the input: "I love working at tiktok", the program should return: "tiktok at working love I".
Input Format
A string containing only uppercase and lowercase letters and a single space.
Output Format
A string with the order of the words reversed.
Example
Input: "I love working at tiktok" Output: "tiktok at working love I"
Example
Input
I love working at tiktok