Advertisement
fireLUFFY

BinarySearch_Stacks_UnixPathResolution

Jul 13th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. //fireLUFFY
  2. //BinarySearch: Stacks->Unix_Path_Resolution
  3.  
  4. ///////////solution////////////
  5.  
  6. vector<string> solve(vector<string>& path) {
  7.     stack<string>s;
  8.     for(int i=0;i<path.size();++i)
  9.     {
  10.         if(s.empty())
  11.         {
  12.             if((path[i]!=".")&&(path[i]!=".."))
  13.             s.push(path[i]);
  14.         }
  15.         else
  16.         {
  17.             if((path[i]!=".")&&(path[i]!=".."))
  18.             s.push(path[i]);
  19.             else
  20.             {
  21.                 if(path[i]=="..")
  22.                 {
  23.                     if(!s.empty())
  24.                     s.pop();
  25.                 }
  26.                 else
  27.                 continue;
  28.             }
  29.         }
  30.     }
  31.     vector<string>v;
  32.     while(!s.empty())
  33.     {
  34.         v.push_back(s.top());
  35.         s.pop();
  36.     }
  37.     reverse(v.begin(),v.end());
  38.     return v;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement