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