LeetCode 151. Reverse Words in a String
题目描述:
Given an input string, reverse the string word by word.
For example, Given s = “
the sky is blue
”, return “blue is sky the
”.Clarification:
- What constitutes a word? A sequence of non-space characters constitutes a word.
- Could the input string contain leading or trailing spaces? Yes. However, your reversed string should not contain leading or trailing spaces.
- How about multiple spaces between two words? Reduce them to a single space in the reversed string.
翻转一个字符串中的单词, 先翻转整个字符串然后再把每一个单词都翻转一次即可. 但是要考虑输入字符串前后的空格和单词间多余空格.
1 | class Solution { |