golang
func simplifyPath(path string) string {
paths := strings.Split(path, "/")
res := make([]string, 0, len(paths))
for _, s := range paths {
switch s {
case "", ".":
case "..":
if len(res) > 0 {
res = res[:len(res)-1]
}
default:
res = append(res, s)
}
}
return "/" + strings.Join(res, "/")
}