Skip to content

Commit 55487fa

Browse files
author
Partho Biswas
committed
388_Longest_Absolute_File_Path
1 parent 34d22bf commit 55487fa

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ I have solved quite a number of problems from several topics. See the below tabl
210210
|30| **[925. Long Pressed Name](https://tinyurl.com/s4jbmmk)** | [Python](https://tinyurl.com/wu6rdaw/925_Long_Pressed_Name.py), [Swift](https://tinyurl.com/wuja3c4/925_Long_Pressed_Name.swift) | --- | Easy | |
211211
|31| **[949. Largest Time for Given Digits](https://tinyurl.com/ux8dk9e)** | [Python](https://tinyurl.com/wu6rdaw/949_Largest_Time_for_Given_Digits.py), [Swift](https://tinyurl.com/wuja3c4/949_Largest_Time_for_Given_Digits.swift) | --- | Easy | Not so easy |
212212
|32| [788. Rotated Digits](https://tinyurl.com/t9gelfm) | [Python](https://tinyurl.com/wu6rdaw/788_Rotated_Digits.py), [Swift](https://tinyurl.com/wuja3c4/788_Rotated_Digits.swift) | --- | Easy | --- |
213+
|33| [388. Longest Absolute File Path](https://tinyurl.com/svfa3rc) | [Python](https://tinyurl.com/wu6rdaw/388_Longest_Absolute_File_Path.py), [Swift](https://tinyurl.com/wuja3c4/388_Longest_Absolute_File_Path.swift) | --- | Medium | --- |
213214

214215

215216
</p>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution(object):
2+
def lengthLongestPath(self, input):
3+
maxPath = 0
4+
paths = [0]
5+
for subDir in input.splitlines():
6+
7+
# getting the depth level of the current subpath
8+
level = subDir.count('\t')
9+
10+
# increasing the size of the array of the parents subpaths, if needed
11+
if level >= len(paths):
12+
paths += [None]
13+
14+
# updating the length of the current depth level
15+
if level > 0:
16+
paths[level] = paths[level - 1] + (len(subDir) - level) + 1
17+
else:
18+
paths[level] = len(subDir)
19+
20+
# updating the maximum length
21+
if '.' in subDir:
22+
maxPath = max(maxPath, paths[level])
23+
24+
return maxPath

0 commit comments

Comments
 (0)