唯一的坑点,"/..."这个示例,"..."是目录名
class Solution {
public:
string simplifyPath(string path) {
deque<string> DQ;
istringstream iss(path);
string word;
while(getline(iss, word, '/')) {
if(!word.empty() && word != "." && word != "..")
DQ.push_back(word);
else if(!word.empty() && word == ".." && !DQ.empty())
DQ.pop_back();
}
if(DQ.empty())
return "/";
else {
string ret;
while(!DQ.empty()) {
ret += "/";
ret += DQ.front();
DQ.pop_front();
}
return ret;
}
}
};