8000 update · beyondyyh/Leetcode@0362d63 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0362d63

Browse files
author
beyondyyh
committed
update
1 parent b557aab commit 0362d63

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

algorithms/mystring/93.restoreIpAddresses.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
// 暴力法,非常暴力,牛逼克拉斯
99
func restoreIpAddresses(s string) []string {
10-
var res []string
10+
res := []string{}
1111
for a := 1; a < 4; a++ {
1212
for b := 1; b < 4; b++ {
1313
for c := 1; c < 4; c++ {
@@ -18,9 +18,8 @@ func restoreIpAddresses(s string) []string {
1818
n3, _ := strconv.Atoi(s[a+b : a+b+c])
1919
n4, _ := strconv.Atoi(s[a+b+c:])
2020
if n1 <= 255 && n2 <= 255 && n3 <= 255 && n4 <= 255 {
21-
var arr []string
22-
arr = append(arr, strconv.Itoa(n1), strconv.Itoa(n2), strconv.Itoa(n3), strconv.Itoa(n4))
23-
IP := strings.Join(arr, ".")
21+
segments := append([]string{}, strconv.Itoa(n1), strconv.Itoa(n2), strconv.Itoa(n3), strconv.Itoa(n4))
22+
IP := strings.Join(segments, ".")
2423
if len(IP) == len(s)+3 {
2524
res = append(res, IP)
2625
}

0 commit comments

Comments
 (0)
0