Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. class Solution(object):
  2. def lengthLongestPath(self, input):
  3. """
  4. :type input: str
  5. :rtype: int
  6. """
  7. string = input.split("\n")
  8. lst = []
  9. longest_string = ""
  10.  
  11. for s in string:
  12. count = s.count('\t')
  13. if (count > 0):
  14. index = s.rfind('\t') # find last occurenct of \t
  15. s = s[index+1:]
  16.  
  17. if count < len(lst):
  18. lst[count] = s
  19. lst = lst[:count + 1]
  20. else:
  21. lst.append(s)
  22.  
  23. curr_string = "/".join(lst)
  24. if len(curr_string) > len(longest_string) and "." in curr_string:
  25. longest_string = curr_string
  26.  
  27. return len(longest_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement