add new solutions

This commit is contained in:
kanna5 2026-01-05 16:48:03 +09:00
parent d798d5e8c9
commit 886b5e0a8e
Signed by: kkyy
GPG key ID: 06332F3965E9B0CF
34 changed files with 1164 additions and 0 deletions

View file

@ -0,0 +1,32 @@
package q71
import "strings"
func simplifyPath(path string) string {
b := strings.Builder{}
fields := strings.FieldsFunc(path, func(r rune) bool { return r == '/' })
p := 0
for i := range fields {
switch fields[i] {
case ".":
continue
case "..":
p = max(p-1, 0)
default:
fields[p] = fields[i]
p++
}
}
for i := range p {
b.WriteByte('/')
b.WriteString(fields[i])
}
if p == 0 {
return "/"
}
return b.String()
}
var _ = simplifyPath