[LeetCode]388. Longest Absolute File Path
来源:互联网 发布:如何设置广电网络网线 编辑:程序博客网 时间:2024/06/06 12:26
https://leetcode.com/problems/longest-absolute-file-path/#/description
找最长的绝对路径字符长度
给:"dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext"
返回:32
stack保存当前前序路径长度
public class Solution { public int lengthLongestPath(String input) { Stack<Integer> stack = new Stack(); int maxLen = 0; // 先push一个! stack.push(0); for (String s : input.split("\n")) { // "\t"就是代表tab!!是一个字符 int level = s.lastIndexOf("\t") + 1; // 因为先push了一个0.所以level + 1去比较 while (level + 1 < stack.size()) { stack.pop(); } // +1表示结尾要加一个"/" int len = stack.peek() + s.length() - level + 1; stack.push(len); if (s.contains(".")) { // -1表示最后一个未见后面应该没有"/" maxLen = Math.max(maxLen, len - 1); } } return maxLen; }}
0 0
- LeetCode—388. Longest Absolute File Path
- LeetCode—388. Longest Absolute File Path
- leetcode -- 388. Longest Absolute File Path
- 388. [LeetCode]Longest Absolute File Path
- [Leetcode]388. Longest Absolute File Path
- 【LeetCode】 388. Longest Absolute File Path
- [LeetCode]388. Longest Absolute File Path
- LeetCode 388. Longest Absolute File Path
- [leetcode]388. Longest Absolute File Path
- leetcode:Longest Absolute File Path
- 【Leetcode】Longest Absolute File Path
- Leetcode Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- Handler vs Timer
- 在Matlab中根据离散点坐标绘制空间曲面
- 奇葩的车祸,保险公司怎么赔啊
- Hibernate 的代码生成插件是 hibernateTools。Mybatis 是 Mybatis generator
- 【图像处理】Photoshop Tags
- [LeetCode]388. Longest Absolute File Path
- RTMP推流及协议学习
- GBK到UTF8编码转换C++实现
- 【图像处理】Apple Tags
- javascript 数组 深拷贝的简易方法(通过concat)
- 机器人操作系统ROS Indigo 入门学习(9)——理解ROS rqt_console和 roslaunch
- leetcode
- G++ 中文使用教程
- 垃圾收集分析(1)-Java对象结构(上)