LeetCode 071 Simplify Path

LeetCode 071 Simplify Path Problem

Download Code
class Solution(object):
    def simplifyPath(self, path):
        """
        :type path: str
        :rtype: str
        """
        result = []
        plist = path.split('/')
        for pos in plist:
            if pos:
                if pos == '..':
                    try:
                        # up one level
                        result.pop()
                    except:
                        # arrive top level
                        result = []
                elif pos != '.':
                    result.append(pos)
        return '/'+'/'.join(result)
Download Simplify Path.py

List of all Simplify Path problems

Leetcode 071 Simplify Path problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.