LeetCode 557. Reverse Words in a String III
题目描述:
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
2
3 Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"Note: In the string, each word is separated by single space and there will not be any extra space in the string.
这么简单的题真的会出现?
由于没有多余的空格,所以用双指针找到下一个空格,翻转当前位置与下一个空格之间的字符,设置左指针为下一个空格的位置+1.
1 | class Solution { |