151. Reverse Words in a String

Posted warmland

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了151. Reverse Words in a String相关的知识,希望对你有一定的参考价值。

没什么说的

 1     public String reverseWords(String s) {
 2         if(s == null || s.length() == 0) {
 3             return "";
 4         }
 5         s = s.replaceAll(" +", " ");
 6         System.out.println(s);
 7         List<String> words = new ArrayList<String>(Arrays.asList(s.split(" ")));
 8         words.remove("");
 9         Collections.reverse(words);
10         return String.join(" ", words);
11     }

 

以上是关于151. Reverse Words in a String的主要内容,如果未能解决你的问题,请参考以下文章

151. Reverse Words in a String

151. Reverse Words in a String

151. Reverse Words in a String

leetcode-Reverse Words in a String-151

LeetCode-151-Reverse Words in s String

151. Reverse Words in a String (String)