LeetCode 388 Longest Absolute File Path

LeetCode 388 Longest Absolute File Path Problem

Download Code
class Solution(object):
    def lengthLongestPath(self, input):
        """
        :type input: str
        :rtype: int
        """
        if input is None or len(input) == 0:
            return 0
        lines = input.split('\n')
        last_level_len = [0] * (len(lines) + 1); max_len = 0
        for line in lines:
            try:
                level = line.rindex('\t') + 1
            except:
                level = 0
            cur_len = last_level_len[level + 1] = last_level_len[level] + len(line) - level + 1
            if '.' in line:
                max_len = max(max_len, cur_len - 1)
        return max_len

if __name__ == '__main__':
    s = Solution()
    print s.lengthLongestPath("dir\n    file.txt")
Download Longest Absolute File Path.py

List of all Longest Absolute File Path problems

Leetcode 388 Longest Absolute File 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.