当前位置:网站首页>2022.4.20-----leetcode. three hundred and eighty-eight
2022.4.20-----leetcode. three hundred and eighty-eight
2022-04-23 01:45:00 【Lu 727】
public static int lengthLongestPath(String input) {
String[] dirs=input.split("\n");// Division
Deque<Integer> stk=new ArrayDeque<>();
int cur=0;// Current path length
int max=0;// Maximum path length
for (String dir : dirs) {
int layer=0;// There are several '\t' Represents the level of the directory
int i;
for (i = 0; dir.charAt(i)=='\t' ; i++) {
layer++;
}
int len=dir.substring(i).length();// The length of the directory name is
// Stack according to the layer of the directory , And update the cur
int n=stk.size();// It's on the second day n-1 layer
for (int j = 0; j < n-layer; j++) {
cur-=stk.pollLast()+1;
}
stk.offer(len);// Add this directory
cur+=len+1;
// Maximum length of file record encountered
if(dir.contains("."))
max=Math.max(max,cur);
}
if(max==0)// No files
return max;
return max-1;// Not before the first directory '/'
}
版权声明
本文为[Lu 727]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230143495428.html
边栏推荐
- Leetcode-阶乘函数后 K 个零
- Update description of the latest process engine flowable 6.7.2
- What are the benefits of writing unit tests using the unit test framework?
- Realize the function of progress bar through layerdrawable
- leetcode771. Gemstones and stones
- How can e-procurement become a value-added function in the supply chain?
- Full Permutation (DFS and next_permutation solution)
- NPM -- configure Taobao image
- What code needs unit testing?
- 01 knapsack problem - and deformation problem
猜你喜欢

Error in face detection and signature of Tencent cloud interface

2022 low voltage electrician examination questions and answers

科技云报道:云计算进入“下半场”,国产云的出路在哪儿?

2022 melting welding and thermal cutting operation certificate examination question simulation examination platform operation

The sixth season of 2022, the perfect children's model IPA national race leads the yuanuniverse track

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

CDR2022首发全新版本性能介绍

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

第六章 使用 matplotlib 绘制热力图

leetcode771. Gemstones and stones
随机推荐
Error in face detection and signature of Tencent cloud interface
The most understandable life cycle of dependency injection
Garlic Junkai company (DFS full arrangement)
d盘分给C盘后,数据库恢复挂起怎么办,求各位解答
Learning methods and career development guide (2022 Edition)
计蒜客(踏青)(染色块问题的DFS和BFS解法)
修改数组(并查集)
Custom numeric input control
Chris LATTNER, father of llvm: the golden age of compilers
Challenges often faced by client project management
2022第六季完美童模 IPA國民賽領跑元宇宙賽道
Unity结合iTextSharp生成PDF 准备dll
无关联进程间通信 —— 命名管道的创建和使用
Qingyan environment and Shenzhen Stock Exchange listing: annual revenue of 180 million and market value of 4.1 billion
C语言实现Base64编码/解码
J-link v9 使用技巧之虚拟串口功能
计蒜客:等边三角形(DFS)
42. Use k3det in mmrotate for rotating target detection, MNN deployment and ncnn deployment
J-Link RTT使用
Leetcode 112 Total path (2022.04.22)