LeetCode 388: Longest Absolute File Path
2017-10-09 13:45
381 查看
class Solution { public int lengthLongestPath(String input) { if (input.length() == 0) return 0; String[] layers = input.split("\n"); int[] stack = new int[layers.length + 1]; int result = 0; for (String s : layers) { int level = s.lastIndexOf("\t") + 1, current = stack[level + 1] = stack[level] + s.length() - level + 1; // Find how many \t, which mean it belongs to which level. stack[level + 1] = stack[level] + s.length() - 1evel + 1 is calculate current level length by removing \t and update the prefix for next level if (s.contains(".")) result = Math.max(result, current - 1); // Check the last file. } return result; } }
相关文章推荐
- Leetcode 388 Longest Absolute File Path
- [leetcode-388]Longest Absolute File Path
- leetcode_388 Longest Absolute File Path
- LeetCode- Longest Absolute File Path
- Longest Absolute File Path -- LeetCode
- Leetcode: Longest Absolute File Path
- [LeetCode] Longest Absolute File Path 最长的绝对文件路径
- 388. [LeetCode]Longest Absolute File Path
- 【Leetcode】Longest Absolute File Path
- Leetcode Longest Absolute File Path
- leetcode:Longest Absolute File Path
- Longest Absolute File Path问题及解法
- Longest Absolute File Path
- [leetcode] 388. Longest Absolute File Path 解题报告
- [Leetcode]388. Longest Absolute File Path
- Longest Absolute File Path
- Longest Absolute File Path
- Leetcode-388. Longest Absolute File Path
- [LeetCode] 388. Longest Absolute File Path 最长的绝对文件路径
- LeetCode 388. Longest Absolute File Path