Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //fireLUFFY
- //BinarySearch: Stacks->Unix_Path_Resolution
- ///////////solution////////////
- vector<string> solve(vector<string>& path) {
- stack<string>s;
- for(int i=0;i<path.size();++i)
- {
- if(s.empty())
- {
- if((path[i]!=".")&&(path[i]!=".."))
- s.push(path[i]);
- }
- else
- {
- if((path[i]!=".")&&(path[i]!=".."))
- s.push(path[i]);
- else
- {
- if(path[i]=="..")
- {
- if(!s.empty())
- s.pop();
- }
- else
- continue;
- }
- }
- }
- vector<string>v;
- while(!s.empty())
- {
- v.push_back(s.top());
- s.pop();
- }
- reverse(v.begin(),v.end());
- return v;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement