Analysis
- Use a stack to record the current path hierarchy, each element in the stack correspond to a folder in the path
- Iterate the input path string and maintain the path stack. parse the sub string between two slashes
- if sub string is /. or empty, do nothing
- if sub string is /.. path stack.pop_back
- if sub string is a folder name, path stack.push_back
No comments:
Post a Comment
Enter you comment