'图解算法数据结构-05替换空格'
This commit is contained in:
parent
c8500c2db7
commit
b5a2852bb0
34
leetcode/图解数据结构/02.替换空格/main.go
Normal file
34
leetcode/图解数据结构/02.替换空格/main.go
Normal file
@ -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."))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user