본문 바로가기

0/leetcode

388. Longest Absolute File Path

반응형

leetcode.com/problems/longest-absolute-file-path/

 

Longest Absolute File Path - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

class Solution:
    def lengthLongestPath(self, input: str) -> int:
        
        tokens = input.split('\n')
        
        if not tokens :
            return 0
        
        d = collections.defaultdict(int)
        output = 0
        
        for t in tokens :
            depth = t.count('\t')
            d[depth] = d[depth-1] + len(t) - depth
            
            if '.' in t :
                output = max(output, d[depth]+depth)
        
        return output
    

 

 

반응형

'0 > leetcode' 카테고리의 다른 글

[October LeetCoding Challenge] 29th - Maximize Distance to Closest Person  (0) 2020.10.30
398. Random Pick Index  (0) 2020.10.27
914. X of a Kind in a Deck of Cards  (0) 2020.10.21
41. First Missing Positive  (0) 2020.09.30
134. Gas Station  (0) 2020.09.24