LeetCode—388. Longest Absolute File Path
来源:互联网 发布:乐高机器人ev3编程 编辑:程序博客网 时间:2024/05/19 19:15
Longest Absolute File Path思路:非常恶心的题目,测试样例提供一个不从某个目录开始,而是从多个目录开始的样例。。题目很简单,注意各种奇怪的案例即可。
GitHub地址:https://github.com/corpsepiges/leetcode
点此进入如果可以的话,请点一下star,谢谢。
<span style="font-size:12px;">public class Solution { private class NodeFile { String name; List<NodeFile> list; int max=0; public NodeFile(String name) { this.name = name; this.list = new ArrayList<NodeFile>(); this.max=name.contains(".")?name.length():0; } } public int lengthLongestPath(String input) { int max=0; String[] strs=input.split("\n"); StringBuffer sb=new StringBuffer(strs[0]); for (int i = 1; i < strs.length; i++) { if (strs[i].substring(0,1).equals("\t")||(strs[i].length()>4&&strs[i].substring(0,4).equals(" "))) { sb.append('\n'+strs[i]); }else{ NodeFile node=structureTreeFile(sb.toString()); if (node.max>max) { max=node.max; } sb=new StringBuffer(strs[i]); } } NodeFile node=structureTreeFile(sb.toString()); if (node.max>max) { max=node.max; } return max; } public NodeFile structureTreeFile(String input) { if (input.length() > 0) { String[] strs = input.split("\n"); StringBuffer sb = new StringBuffer(); NodeFile ans = new NodeFile(strs[0]); int otherMax=0; for (int i = 1; i < strs.length; i++) { String s=strs[i]; if (s.length()>4&&s.substring(0,4).equals(" ")) { s=s.substring(4); }else{ s=s.substring(1); } if (s.contains("\t")) { sb.append("\n"+s); } else { NodeFile node = structureTreeFile(sb.toString()); if (node != null) { ans.list.add(node); if (node.max>otherMax) { otherMax=node.max; } } sb = new StringBuffer(s); } } NodeFile node = structureTreeFile(sb.toString()); if (node != null) { ans.list.add(node); if (node.max>otherMax) { otherMax=node.max; } } if (otherMax!=0) { ans.max=ans.name.length()+1+otherMax; } return ans; } return null; }}</span>
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
- Data学习
- 设置访问的主页面
- 查看eclipse ADT SDK JDK版本号(转的,应该是加载adt和 sdk后才能看到)
- 安装cx_Oracle模块步骤以及出现问题解决,还有中文乱码情况
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- LeetCode—388. Longest Absolute File Path
- Android-->相册,摄像头获取图片,图片路径,以及剪裁图片
- Java面试
- PHP如何实现网址伪静态(图文解说)
- java多线程学习--线程栈
- infragistics guid 获取选中行
- 那些年撸代码遇到的让人心酸bug-------js验证码刷新
- Android之Volley的使用
- protocol buffer使用中的问题This is supposed to be overridden by subclasses