From f0ff78a4e6a59ddc268ece9b2d90430c74aa6e8e Mon Sep 17 00:00:00 2001 From: Omooo <869759698@qq.com> Date: Thu, 18 Jun 2020 09:08:09 +0800 Subject: [PATCH] =?UTF-8?q?Create=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 --- .../Algorithm/剑指 Offer/字符串相关.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 blogs/Algorithm/剑指 Offer/字符串相关.md diff --git a/blogs/Algorithm/剑指 Offer/字符串相关.md b/blogs/Algorithm/剑指 Offer/字符串相关.md new file mode 100644 index 0000000..e9236e0 --- /dev/null +++ b/blogs/Algorithm/剑指 Offer/字符串相关.md @@ -0,0 +1,26 @@ +--- +字符串相关 +--- + +[05. 替换空格](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) + +```java +class Solution { + + public String replaceSpace(String s) { + StringBuilder builder = new StringBuilder(); + int i = 0; + while (i < s.length()) { + char c = s.charAt(i); + if (c == ' ') { + builder.append("%20"); + } else { + builder.append(c); + } + i++; + } + return builder.toString(); + } +} +``` +