Hi, this is Shunchi!

  • Home

  • Tags0

  • Archives267

  • Categories0

  • Curricula

  • DSA

  • LeetCode_Notes

  • Interviews

  • General

  • Resume

Untitled

Posted on 2020-05-10 | Edited on 2021-01-22

https://leetcode.com/problems/reverse-words-in-a-string/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// class Solution {
// public String reverseWords(String s) {
// String[] sarr=s.trim().split(" ");
// int len=sarr.length;
// String res="";
// for(int i=len-1;i>=0;i--){
// if(sarr[i].length()!=0) res+=sarr[i]+" ";
// }
// return res.trim();
// }
// }
class Solution {
public String reverseWords(String s) {
List<String> wordList=Arrays.asList(s.trim().split("\\s+"));
Collections.reverse(wordList);
return String.join(" ",wordList);
}
}

<1…214215216…267>
ShunchiZhou

ShunchiZhou

267 posts
RSS
GitHub E-Mail Gitbook Linkedin
© 2024 ShunchiZhou
Powered by Hexo v5.4.0
|
0%