388 Longest Absolute File Path 最长的绝对文件路径
详见: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 最长的绝对文件路径的更多相关文章
- [LeetCode] 388. Longest Absolute File Path 最长的绝对文件路径
		
Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...
 - [LeetCode] Longest Absolute File Path 最长的绝对文件路径
		
Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...
 - 【LeetCode】388. Longest Absolute File Path 解题报告(Python)
		
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 日期 题目地址:https://leetcode. ...
 - 【leetcode】388. Longest Absolute File Path
		
题目如下: Suppose we abstract our file system by a string in the following manner: The string "dir\ ...
 - 388. Longest Absolute File Path
		
就是看哪个文件的绝对路径最长,不是看最深,是看最长,跟文件夹名,文件名都有关. \n表示一波,可能存在一个文件,可能只有文件夹,但是我们需要检测. 之后的\t表示层数. 思路是如果当前层数多余已经有的 ...
 - [Swift]LeetCode388. 文件的最长绝对路径 | Longest Absolute File Path
		
Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...
 - 最长的文件路径 Longest Absolute File Path
		
2018-07-30 22:05:52 问题描述: 问题求解: 本题个人感觉还是挺有意思的,题目要求的是最长的文件路径,其实是需要keep tracking路径长度,如果出现文件则需要进行比较,看是否 ...
 - Longest Absolute File Path
		
Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...
 - Leetcode: Longest Absolute File Path
		
Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...
 
随机推荐
- Balance POJ - 1837  地推
			
Gigel has a strange "balance" and he wants to poise it. Actually, the device is different ...
 - codevs——6221 数的统计
			
6221 数的统计 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 白银 Silver 题解 题目描述 Description 有一个人名字叫A,B总喜欢打他. 这 ...
 - JAVA初级复习知识点归纳
			
JDK的安装: 下载.安装 配置环境变量 a) path:.;%JAVA_HOME%\bin; b) JAVA_HOME:JDK的安装目录 c) classpath JDK和JRE和JVM: JAVA ...
 - Ubuntu 16.04硬盘有坏道,开机显示blk_update_request:I/0 error
			
可以尝试以下方式解决: 1.检查坏道(效果明显,但是比较慢,检查出来并没有什么用,只是知道有坏块) sudo badblocks -s -v -o /root/bb.log /dev/sda1 2.快 ...
 - Ubuntu 16.04中iptables的工具简介(iptables/iptables-restore/iptables-xml/iptables-apply/iptables-save)
			
Ubuntu 16.04中安装的iptables版本为1.6.0,官方参考:http://www.linuxfromscratch.org/blfs/view/cvs/postlfs/iptables ...
 - Ubuntu 16.04 GNOME在桌面左侧添加启动器(Launcher)
			
安装Dash to Dock: git clone https://github.com/micheleg/dash-to-dock.git cd dash-to-dock/ make make in ...
 - 在GNS3下使用Cisco SDM 的教程
			
安装步骤: 1..先安装jre-6u17-windows-i586se (最新版的)如图: 点击安装,直到安装完成. © 2.安装SDM2.5中文版SDM-V25 如图 : 出现欢迎安装向导,点击下一 ...
 - java实现floyd统计天津地铁的网站距离
			
一:说明 (1)使用floyd实现各个网站的计算记录和路径 (2)网站获取和初始距离依据外部文件得到 (3)结果以外部文件的形式存储 (4)网站间转乘,觉得初始值也为1 (5)代码凝视比較具体,如有疑 ...
 - 基于MFC的一个简单计算器
			
写一个简单的计算器并不是什么很难的事,主要目的是要通过这个程序来学习和分析其中的核心算法.这个简易计算器的核心部分就是对输入的表达式的正确性判断与求值,其中包括对表达式的解析.中缀表达式转后缀表达式. ...
 - SQLite数据库基本操作
			
SQLite 是一个开源的嵌入式关系数据库,实现自包容.零配置.支持事务的SQL数据库引擎. 其特点是高度便携.使用方便.结构紧凑.高效.可靠. 与其他数据库管理系统不同,SQLite 的安装和运行非 ...