Update 字符串相关.md

master
Omooo 4 years ago
parent 80c22a450b
commit 31666519e2
  1. 19
      blogs/Algorithm/剑指 Offer/字符串相关.md

@ -74,3 +74,22 @@ class Solution {
} }
``` ```
[Offer 58 - I. 翻转单词顺序](https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/)
```java
class Solution {
public String reverseWords(String s) {
String[] strings = s.trim().split(" ");
StringBuilder sb = new StringBuilder();
for (int i = strings.length - 1; i >= 0; i--) {
if (strings[i].equals("")) {
continue;
}
sb.append(strings[i]).append(" ");
}
return sb.toString().trim();
}
}
```

Loading…
Cancel
Save