Re: [闲聊] 每日LeetCode

楼主: Rushia (みけねこ的鼻屎)   2022-11-13 15:49:37
151. 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:
作者: hahaha021225 (安安你好)   2022-11-13 15:51:00
每天刷?
作者: sustainer123 (caster)   2022-11-13 15:53:00
大师
作者: itoumashiro (佩可咪口爱的结晶)   2022-11-13 16:03:00
龙大咧

Links booklink

Contact Us: admin [ a t ] ucptt.com