题目

https://leetcode.com/problems/longest-absolute-file-path/

题解


没有思路的时候,看 Related Topics,知道这题在考察什么了,顺着这个方向想就好了。

顺便贴一下草稿:

class Solution {public int lengthLongestPath(String input) {String[] list = input.split("\\n");Stack<Integer> stack = new Stack<>(); // 栈中记录累计长度int maxLen = 0;for (String s : list) {int d = getDepth(s); // 获取当前目录的depthwhile (d < stack.size()) { // 不断出栈,直到当前目录被可以包含在栈顶元素中stack.pop();}if (s.contains(".")) { // filemaxLen = Math.max((stack.isEmpty() ? -1 : stack.peek()) + s.length() - d + 1, maxLen); // -1是由于根目录没有前导/,+1是计算包含前导/的长度} else { // dirstack.push((stack.isEmpty() ? -1 : stack.peek()) + s.length() - d + 1);}}return maxLen;}public int getDepth(String s) {int d = 0;while (s.startsWith("\t")) {d++;s = s.substring(1);}return d;}
}

leetcode 388. Longest Absolute File Path | 388. 文件的最长绝对路径(栈+DFS)相关推荐

  1. Leet Code OJ 388. Longest Absolute File Path [Difficulty: Medium]

    题目 Suppose we abstract our file system by a string in the following manner: The string "dir\n\t ...

  2. [Swift]LeetCode388. 文件的最长绝对路径 | Longest Absolute File Path

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  3. 文件系统中文件的最长(字符数)绝对路径 Longest Absolute File Path

    为什么80%的码农都做不了架构师?>>>    问题: Suppose we abstract our file system by a string in the followin ...

  4. LeetCode Longest Absolute File Path(栈和前缀和解法)

    问题:给出一个字符串表示的文件目录信息,使用\n\t...来表示层次关系.要求最长的绝对文件路径长度 思路: 方法一使用栈,当栈为空时,将文件信息直接放入栈中,如果当前文件的层次比栈顶的层次深则直接入 ...

  5. springboot打成jar后获取resources下文件失败, cannot be resolved to absolute file path because it does not resid

    读取resources下的文件quotaShow.jasper 本地开发环境能正常下载: ClassPathResource resource = new ClassPathResource(&quo ...

  6. LeetCode 388. 文件的最长绝对路径(不用栈,前缀和)

    1. 题目 假设我们以下述方式将我们的文件系统抽象成一个字符串: 字符串 "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext" 表示: dirsubd ...

  7. 导出报错cannot be resolved to absolute file path because it does not reside in the file system

    SpringBoot项目打包部署,读取jar里面的文件报错500,异常日志关键提示 cannot be resolved to absolute file path because it does n ...

  8. 问题备忘: class path resource [xx] cannot be resolved to absolute file path because it does not reside

    问题描述 测试服务的版本是Spring Cloud Dalston.SR5 在Spring Boot中配置https时,代码如下: @Bean@ConditionalOnExpression(&quo ...

  9. 388. 文件的最长绝对路径

    链接:388. 文件的最长绝对路径 题解: class Solution {public:vector<string> split(string src, string delimeter ...

最新文章

  1. Android之linux之基础建设之窗口系统
  2. 有一种努力叫:靠 自 己!
  3. 4.录屏软件录屏端和接收端程序
  4. C++顺序容器之deque初探
  5. cocos ScrollView(滚动容器)加载大量item导致的卡顿问题解决方案
  6. 世界上迄今为止最安全的加密算法
  7. 学会了很多计算机小技巧,超实用的八个电脑小技巧,全都学会让你成为电脑高手...
  8. push和unshift方法
  9. windows下apache+php+mysql 环境配置方法
  10. Vue多页应用脚手架
  11. java ide下载_jGRASP|轻量级Java IDE(jGRASP)下载v2.0.4.03官方版 - 欧普软件下载
  12. java 64bit_java9 64位 官方最新版
  13. 移动应用数据统计平台(之一)
  14. hash函数的基本知识
  15. mini2440硬件篇之Nand Flash
  16. 一位华尔街金融大鳄的选股模型
  17. C语言-算术表达式-加,减,乘,除,求余
  18. 坐式养生八段锦口诀及练法图解
  19. 【ML】线性回归 [多因子](LinearRegression)实践(基于sklearn)
  20. 计算机试题技巧,计算机基础试题带答案3技巧.doc

热门文章

  1. 2019ICPC(南昌) - Hello 2019(动态规划+线段树维护矩阵)
  2. 整数域上的多项式辗转相除
  3. 梅朵是藏语鲜花的意思
  4. 反汇编RETN 0x0c的理解
  5. memmove和memcpy
  6. WebSoket 的广泛应用
  7. scrapy使用cookie的三种方式
  8. 40个Java多线程问题详解复习
  9. Python中的进程间通信
  10. 技术实战 —— 快速实现语聊房搭建