楼主:
Rushia (みけねこ的鼻屎)
2022-11-13 15:49:37151. Reverse Words in a String
给与一个字串s,将句子里的所有单字(word)顺序颠倒,并去除大于一个和在头尾的空格。
Example:
Input: s = "the sky is blue"
Output: "blue is sky the"
Input: s = " hello world "
Output: "world hello"
Input: s = "a good example"
Output: "example good a"
思路:
1.把字串s用正则表达式依据空白切开成多个部分
2.从尾放到头,如果被切开的字串不是空白就appende该字串并加上空白分隔符。
3.最后把多出的空白分隔符删除即可。
Java Code: