当前位置:网站首页>2022.4.20-----leetcode.388
2022.4.20-----leetcode.388
2022-04-23 01:44:00 【路Lu727】
public static int lengthLongestPath(String input) {
String[] dirs=input.split("\n");//分割
Deque<Integer> stk=new ArrayDeque<>();
int cur=0;//当前路径长度
int max=0;//最大路径长度
for (String dir : dirs) {
int layer=0;//有几个'\t'代表该目录在第几层
int i;
for (i = 0; dir.charAt(i)=='\t' ; i++) {
layer++;
}
int len=dir.substring(i).length();//该目录名称长度
//根据该目录所处层进行出栈,并更新cur
int n=stk.size();//表示当前在第n-1层
for (int j = 0; j < n-layer; j++) {
cur-=stk.pollLast()+1;
}
stk.offer(len);//添加该目录
cur+=len+1;
//遇到文件记录最大长度
if(dir.contains("."))
max=Math.max(max,cur);
}
if(max==0)//没有文件
return max;
return max-1;//第一个目录前没有'/'
}
版权声明
本文为[路Lu727]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_60466670/article/details/124355722
边栏推荐
- [经验教程]支付宝余额自动转入余额宝怎么设置关闭取消支付宝余额自动转入余额宝?
- J-Link RTT使用
- Oracle database query lock table SQL script and delete lock information script (necessary for database development ETL and DBA)
- Futr3d: a unified 3D detection framework for sensor fusion
- 稳定币是让公链加速死亡或者取代BTC的超级机会?
- Detonate the bomb (DFS)
- NPM -- configure Taobao image
- 全排列(DFS和next_permutation解法)
- Encrypted compressed backup bat script
- 哪些代码需要做单元测试?
猜你喜欢

DFS parity pruning

Technology cloud report: cloud computing has entered the "second half". Where is the way out for domestic cloud?

2022第六季完美童模 IPA国民赛领跑元宇宙赛道

J-link v9 使用技巧之虚拟串口功能

C语言中如何“指名道姓”的进行初始化

Soatest preliminary understanding

计蒜客:数独(DFS)

Redis实现分布式锁

The most easy to understand service container and scope of dependency injection

leetcode771. Gemstones and stones
随机推荐
安装mysql出问题求解决
最长公共子序列(记录路径版)
Unity combines itextsharp to generate PDF preparation DLL
CDR2022首发全新版本性能介绍
Redis implements distributed locks
.NET单元测试第一篇:常见.NET单元测试框架有哪些?
Modify array (and search set)
Completely uninstall antidote 10? What if the antidote uninstall is not clean?
C语言中如何“指名道姓”的进行初始化
Itextsharp page setup
Self taught programming, don't read theory books foolishly, programmer: it's all left over by others
Error in face detection and signature of Tencent cloud interface
Garlic customer: equilateral triangle (DFS)
In the context of Internet plus, how can enterprises innovate customer service?
Blocking type of gbase 8s concurrency control
第六章 使用 matplotlib 绘制热力图
客户端项目管理经常面临的挑战
修改数组(并查集)
NR polar code 七- SCL(succesive cancellation list decoding)
npm——配置淘宝镜像