Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- **/
- class Solution {
- public:
- string simplifyPath(string path) {
- string res, temp;
- vector<string>st;
- istringstream in(path);
- string word;
- while( getline(in, word, '/') )
- {
- if( word == "" || word == "." ) continue;
- if( word == ".." && !st.empty() ) st.pop_back();
- else if(word != "..")st.push_back(word);
- }
- for(string s:st) res += "/" + s;
- return st.empty() ? "/" : res;
- }
- };
Add Comment
Please, Sign In to add comment