题目描述
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
1 | Input: "Let's take LeetCode contest" |
这题需要先根据' '
来切分字符串,然后对每一个切分后的元素进行反转,反转可以用reverse(s.begin(), s.end())
。
切分字符串的时候,我使用了字符串流,然后使用getline函数来进行切割。
代码实现
1 | class Solution { |