# 做这题的时候对比了一下之前的代码，为什么差距这么大？

## 题意

Input: "/home/" Output: "/home" Explanation: Note that there is no trailing slash after the last directory name. Input: "/../" Output: "/" Explanation: Going one level up from the root directory is a no-op, as the root level is the highest level you can go. Input: "/a/../../b/../c//.//" Output: "/c"

## 题解

class Solution:     def simplifyPath(self, path: str) -> str:         folders = []         # 按照/分割         fs = path.split("/")         for f in fs:             # .直接跳过即可，不会影响结果             if f == '.':                 continue             # 如果是..需要判断是否在顶层             # 不在顶层的话抛弃掉最后插入的文件夹             if f == '..':                 if len(folders) > 0:                     folders.pop()             elif f != '':                 folders.append(f)                          return '/' + '/'.join(folders)

## 总结

class Solution { public:     vector split(string & path) {         vector vt;         string cur = "";           // 遍历所有字符         for (int i = 0; i < path.length(); i++) {               // 如果是/ 说明需要把之前的内容放入vector             if (path[i] == '/') {                   // 如果是空或者是.就跳过，因为.没有意义                 if (cur != "" && cur != ".") {                     vt.push_back(cur);                 }                 cur = "";             }else cur = cur + path[i];         }           // 要注意最后遗留的字符串         if (cur != "" && cur != ".") vt.push_back(cur);         return vt;     }     string simplifyPath(string path) {         vector dirs = split(path);         string ret = "";           // 存储文件的结构         vector paths;         for (string str : dirs) {               // 如果是.. 则返回上级             if (str == "..") {                 if (paths.size() > 0) {                     paths.pop_back();                 }               // 否则则填入vector，表示合法             }else paths.push_back(str);         }         for (string str : paths) ret = ret + "/" + str;         if (ret == "") return "/";         return ret;     } };