MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / simplifyPath

Function simplifyPath

tasks/71.go:12–42  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

10}
11
12func simplifyPath(path string) string {
13 start := 0
14 var ret []string
15 for start < len(path) {
16 for ; start < len(path) && path[start] == '/'; start++ {
17 }
18 end := start
19 for ; end < len(path) && path[end] != '/'; end++ {
20 }
21 s := path[start:end]
22 if s == ".." {
23 if len(ret) > 0 {
24 ret = ret[:len(ret)-1]
25 }
26 } else {
27 if s != "." && s != "" {
28 ret = append(ret, s)
29 }
30 }
31 start = end + 1
32 }
33
34 if len(ret) == 0 {
35 return "/"
36 }
37 answ := ""
38 for _, el := range ret {
39 answ += "/" + el
40 }
41 return answ
42}
43
44// func putInRet(path, str &string, start, end int) {
45// path +

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected