Skip to content

Commit

Permalink
Merge pull request youngyangyang04#2339 from gdstzmy/master
Browse files Browse the repository at this point in the history
Update 替换数字, 右旋字符串的Go语言写法
  • Loading branch information
youngyangyang04 authored Nov 19, 2023
2 parents b87b2bf + 972ca2d commit 2e33887
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
21 changes: 21 additions & 0 deletions problems/kama54.替换数字.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ class Main {
```

### Go:
````go
package main

import "fmt"

func main(){
var strByte []byte

fmt.Scanln(&strByte)

for i := 0; i < len(strByte); i++{
if strByte[i] <= '9' && strByte[i] >= '0' {
inserElement := []byte{'n','u','m','b','e','r'}
strByte = append(strByte[:i], append(inserElement, strByte[i+1:]...)...)
i = i + len(inserElement) -1
}
}

fmt.Printf(string(strByte))
}
````



Expand Down
28 changes: 28 additions & 0 deletions problems/kama55.右旋字符串.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,34 @@ public class Main {


### Go:
```go
package main
import "fmt"

func reverse (strByte []byte, l, r int){
for l < r {
strByte[l], strByte[r] = strByte[r], strByte[l]
l++
r--
}
}


func main(){
var str string
var target int

fmt.Scanln(&target)
fmt.Scanln(&str)
strByte := []byte(str)

reverse(strByte, 0, len(strByte) - 1)
reverse(strByte, 0, target - 1)
reverse(strByte, target, len(strByte) - 1)

fmt.Printf(string(strByte))
}
```


### JavaScript:
Expand Down

0 comments on commit 2e33887

Please sign in to comment.