天天看點

Leetcode Reverse Words in a String

Given an input string, reverse the string word by word.

For example,

Given s = "<code>the sky is blue</code>",

return "<code>blue is sky the</code>".

此題要注意的幾個情況是:

(1)輸入字元串可能含有字首0和字尾0

(2)字元串中每個單詞之間可能含有多個空格

(3)字元串是空串

(3)字元串隻有一個單詞

此題主要是根據空格分隔單詞,然後将分隔後單詞的順序逆轉一下即可

繼續閱讀