leetcode simplify path
用vector代替stack
class Solution { public: vector<string>v1; string simplifyPath(string path) { v1.clear(); string s; string temp; for(int i=0;i<path.size();) { if(path[i]=='/') { int j=i+1; temp=""; for(;j<path.size()&&path[j]!='/';j++) { if(path[j]=='.'&&path[j+1]=='.') { if(v1.size()!=0) v1.pop_back(); j=j+2; break; } temp+=path[j]; } if(temp!=""&&temp!=".")v1.push_back(temp); i=j; } } if(v1.size()==0) s+='/'; for(int i=0;i<v1.size();i++) { s=s+'/'+v1[i]; } return s; } };