详见: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. 2017-10-02-morning

    T1 一道图论神题(god) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图 ...

  2. 图片在 canvas 中的 选中/平移/缩放/旋转,包含了所有canvas的2D变化,让你认识到数学的重要性

    1.介绍 canvas 已经出来好久了,相信大家多少都有接触. 如果你是前端页面开发/移动开发,那么你肯定会有做过图片上传处理,图片优化,以及图片合成,这些都是可以用 canvas 实现的. 如果你是 ...

  3. react 服务器端渲染 ssr 中 localstorage/history/window is not defined 解决方案

    1.原因 ssr 会在后端执行组件的 componentWillMount 以及在它这个生命周期之前的生命周期 也就是说 ssr 阶段是不会执行 componentDidMount 方法的 当你在 c ...

  4. fuse-dfs挂载hdfs实录

    部署安装了最新稳定版hadoop2.2.0.然后在网上找来fuse-dfs编译教程.可是最后失败了.至今原因未知--,错误描写叙述为:Transport endpoint is not connect ...

  5. 怎样用fiddler2捕获移动设备上的http或者https请求

    调试移动设备上的问题.看不到发送的请求和得到的响应是比較难过的,fiddler能够实现样的功能. 原理: 在PC上启动fiddler.将手持设备的网络代理改成fiddler. 这样全部的请求和响应都经 ...

  6. makefile中的一点知识

    makefile文件里以下这一部分展开是什么样的呢? .. . mytarget=foo  $(mytarget): $(mytarget).c        gcc -o $(mytarget) $ ...

  7. Redis开源项目的终极杀手? ——CRUG解读Redis开源协议变更

    引言: 数据库制造商 Redis Labs 本周将公司开发的Redis 模块从 AGPL 迁移到将 Apache v2.0 与 Commons Clause 相结合的许可证,对许可证涵盖的软件作了限制 ...

  8. CSP 201703-4 地铁修建【最小生成树+并查集】

    问题描述 试题编号: 201703-4 试题名称: 地铁修建 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 A市有n个交通枢纽,其中1号和n号非常重要,为了加强运输能力,A市 ...

  9. TFLearn 在给定模型精度时候提前终止训练

    拿来主义:看我的代码,我是在模型acc和验证数据集val_acc都达到99.8%时候才终止训练. import numpy as np import tflearn from tflearn.laye ...

  10. 国产手机没有google services 和google play崩溃,判断google services是否存在

    public static boolean isGooglePlayServiceAvailable (Context context) { int status = GooglePlayServic ...