File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class Solution {
2
+ public int lengthLongestPath (String input ) {
3
+ String [] entities = input .split ("\n " );
4
+ int maxLen = 0 ;
5
+ int curLvl = 0 ;
6
+ String curPath = "" ;
7
+
8
+ for (int i = 0 ; i < entities .length ; i ++) {
9
+ int tab = entities [i ].length () - entities [i ].replace ("\t " , "" ).length ();
10
+
11
+ // adjustment to current path
12
+ while (tab < curLvl ) {
13
+ curPath = curPath .substring (0 , curPath .lastIndexOf ("/" ));
14
+ curLvl --;
15
+ }
16
+
17
+ // add dir/file to path
18
+ curPath += "/" + entities [i ].replace ("\t " , "" );
19
+ curLvl ++;
20
+
21
+ System .out .println (curPath );
22
+
23
+ if ((curPath .length () > maxLen ) && curPath .contains ("." )) {
24
+ maxLen = curPath .length ();
25
+ }
26
+ }
27
+
28
+ if (maxLen > 0 ) {
29
+ return (maxLen -1 );
30
+ } else {
31
+ return 0 ;
32
+ }
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments