From b5a2852bb0806559e1086ebc637459aea363be24 Mon Sep 17 00:00:00 2001 From: zhuyijun Date: Wed, 31 Mar 2021 10:12:29 +0800 Subject: [PATCH] =?UTF-8?q?'=E5=9B=BE=E8=A7=A3=E7=AE=97=E6=B3=95=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=93=E6=9E=84-05=E6=9B=BF=E6=8D=A2=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- leetcode/图解数据结构/02.替换空格/main.go | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 leetcode/图解数据结构/02.替换空格/main.go diff --git a/leetcode/图解数据结构/02.替换空格/main.go b/leetcode/图解数据结构/02.替换空格/main.go new file mode 100644 index 0000000..08b983c --- /dev/null +++ b/leetcode/图解数据结构/02.替换空格/main.go @@ -0,0 +1,34 @@ +/* + * @Description: + * @Version: 2.0 + * @Autor: zhuyijun + * @Date: 2021-03-30 22:22:28 + * @LastEditors: zhuyijun + * @LastEditTime: 2021-03-30 22:45:54 + */ +package main +import "fmt" + +/** +剑指 Offer 05. 替换空格 +请实现一个函数,把字符串 s 中的每个空格替换成"%20"。 + +输入:s = "We are happy." +输出:"We%20are%20happy." + */ +func replaceSpace(s string) string { + var temp string + h := []byte(s) + for _,i :=range h{ + if " " == string(i) { + temp += "%20" + }else{ + temp += string(i) + } + } + return temp +} + +func main() { + fmt.Print(replaceSpace("We are happy.")) +} \ No newline at end of file