Reverse the word order · 反转单词顺序
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Reverse the word order
Given a sentence of space-separated words, return the words in reverse order: the quick brown → brown quick the. Split on spaces with s.split(" "), then build the result from the last word to the first. A StringBuilder is the tidy way to join them.
中文
反转单词顺序
给定一个由空格分隔的句子,按相反顺序返回这些单词:the quick brown → brown quick the。用 s.split(" ") 按空格拆分,然后从最后一个单词到第一个构建结果。用 StringBuilder 来拼接最为整洁。
Complete reverseWords(String s) so it returns the space-separated words in reverse order. Example: the quick brown becomes brown quick the. · 完成 reverseWords(String s),把以空格分隔的单词按相反顺序返回。例如:the quick brown 变成 brown quick the。
Click Run to see the output here. · 点击“运行”查看此处输出。