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

C++:

class Solution {
public:
int lengthLongestPath(string input) {
int res = 0, n = input.size(), level = 0;
unordered_map<int, int> m {{0, 0}};
for (int i = 0; i < n; ++i)
{
int start = i;
while (i < n && input[i] != '\n' && input[i] != '\t')
{
++i;
}
if (i >= n || input[i] == '\n')
{
string t = input.substr(start, i - start);
if (t.find('.') != string::npos)
{
res = max(res, m[level] + (int)t.size());
}
else
{
++level;
m[level] = m[level - 1] + (int)t.size() + 1;
}
level = 0;
}
else
{
++level;
}
}
return res;
}
};

参考:https://www.cnblogs.com/grandyang/p/5806493.html

388 Longest Absolute File Path 最长的绝对文件路径的更多相关文章

  1. [LeetCode] 388. Longest Absolute File Path 最长的绝对文件路径

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

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

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

  3. 【LeetCode】388. Longest Absolute File Path 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 日期 题目地址:https://leetcode. ...

  4. 【leetcode】388. Longest Absolute File Path

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

  5. 388. Longest Absolute File Path

    就是看哪个文件的绝对路径最长,不是看最深,是看最长,跟文件夹名,文件名都有关. \n表示一波,可能存在一个文件,可能只有文件夹,但是我们需要检测. 之后的\t表示层数. 思路是如果当前层数多余已经有的 ...

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

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

  7. 最长的文件路径 Longest Absolute File Path

    2018-07-30 22:05:52 问题描述: 问题求解: 本题个人感觉还是挺有意思的,题目要求的是最长的文件路径,其实是需要keep tracking路径长度,如果出现文件则需要进行比较,看是否 ...

  8. Longest Absolute File Path

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

  9. Leetcode: Longest Absolute File Path

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

随机推荐

  1. js数组转换成json串 (JSON.stringify)

    例如: var giftlist[1490011777] = []; giftlist[1490011777]['id'] = 1490011777; giftlist[1490011777]['na ...

  2. AOJ731(不等式)

    题意:有n(n<=100)个石头,每个石头的价值在Ai~Bi(1<=Ai<=Bi<=10000)之间,将这些石头分给两个人,求两个人的最大总价值差的最小值 分析: 与一般的求最 ...

  3. Java 添加、更新和移除PDF超链接

    简介 PDF超链接用一个简单的链接包含了大量的信息,满足了人们在不占用太多空间的情况下渲染外部信息的需求.下面将介绍通过Java 在PDF中添加.更新和移除超链接. (一)工具使用: Free Spi ...

  4. list循环删除单个元素

    摘自https://www.cnblogs.com/pcheng/p/5336903.html JAVA中循环删除list中元素的方法总结 JAVA中循环遍历list有三种方式for循环.增强for循 ...

  5. Ubuntu 16.04在搭建Redis Cluster搭建时,使用gem install redis时出现:ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /var/lib/gems/2.3.0 directory.

    注意:千万不要使用sudo来执行gem install redis. 解决方法: sudo apt-get update sudo apt-get install git-core curl zlib ...

  6. JSP基础教程:tutorialspoint-jsp

    来自turorialspoint的JSP基础教程(英文),官网:https://www.tutorialspoint.com/jsp/index.htm 这个教程在国内已经被翻译成中文(不过是属于机器 ...

  7. 微信小程序 wafer2框架摘要

    微信小程序 wafer2框架摘要 帮助文档:https://github.com/tencentyun/wafer2-startup/wiki 使用了knex.js进行数据库交互,使用了koa.js进 ...

  8. JAVA程序—HelloWorld 的编译运行

    在我们写好我们的"HelloWorld.java",并且搭建好JAVA的开发环境过后,便可以运行这个JAVA程序了. 具体如何实现,让我们来看看: 打开DOS 通过DOS命令转到& ...

  9. X-pack-6.2.4破解

    1.前言: X-pack是elasticsearch的一个扩展包,将安全,警告,监视,图形和报告功能捆绑在一个易于安装的软件包中,虽然x-pack被设计为一个无缝的工作,但是你可以轻松的启用或者关闭一 ...

  10. 运行shell脚本报错 &#39;\357\273\277&#39;: command not found 解决的方法

    1,删除BOM,在vi以下运行以下的命令就可以 :set nobomb 2,原因: 所谓BOM,全称是Byte Order Mark.它是一个Unicode字符,通常出如今文本的开头,用来标识字节序( ...