当前位置: 首页 > news >正文

C++ | Leetcode C++题解之第388题文件的最长绝对路径

题目:

题解:

class Solution {
public:int lengthLongestPath(string input) {int n = input.size();int pos = 0;int ans = 0;vector<int> level(n + 1);while (pos < n) {/* 检测当前文件的深度 */int depth = 1;while (pos < n && input[pos] == '\t') {pos++;depth++;}/* 统计当前文件名的长度 */   int len = 0; bool isFile = false;     while (pos < n && input[pos] != '\n') {if (input[pos] == '.') {isFile = true;}len++;pos++;}/* 跳过换行符 */pos++;if (depth > 1) {len += level[depth - 1] + 1;}if (isFile) {ans = max(ans, len);} else {level[depth] = len;}}return ans;}
};

http://www.mrgr.cn/news/16855.html

相关文章:

  • Ansible自动化运维项目
  • 栈和队列的习题详解(1):有效的括号
  • 火语言RPA流程组件介绍--浏览选择文件夹
  • 算法设计与分析:实验六 图论——最大流应用问题
  • 地震微分方程代码 - 第一部分
  • Python虚拟环境创建和使用总结
  • python语言基础(五)--面向对象和三大特征
  • SqlDataAdapter和SqlDataReader的区别
  • 深入理解堆排序算法及其时间复杂度分析
  • HTB-Crocodile(FTP和web综合利用)
  • Matrix:重塑APM领域,以简驭繁的性能监控新纪元
  • 初等数学几百年重大错误:N各元n的对应n+1的全体是N的真子集N+——百年病态集论的症结
  • 2024年8月总结及随笔之逝
  • [免越狱]FLEXTool/FLEX 炫酷功能怎么添加到目标App
  • Python enumerate()函数详解
  • Flask中的g的作用
  • 旋转排序:搜索算法
  • git branch 不显示分支名称
  • docker实战基础一
  • 计算机病毒特点有哪些