From 31666519e2975a3badc34bd60c37a910a9e23ac4 Mon Sep 17 00:00:00 2001 From: Omooo <869759698@qq.com> Date: Wed, 24 Jun 2020 08:57:34 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=9B=B8?= =?UTF-8?q?=E5=85=B3.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blogs/Algorithm/剑指 Offer/字符串相关.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/blogs/Algorithm/剑指 Offer/字符串相关.md b/blogs/Algorithm/剑指 Offer/字符串相关.md index 5642db8..d080a5a 100644 --- a/blogs/Algorithm/剑指 Offer/字符串相关.md +++ b/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(); + } +} +``` +