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 ...
随机推荐
- Educational Codeforces Round 41 B、C、D
http://codeforces.com/contest/961 B题 可以将长度为k的连续区间转化成1 求最大和 解析 简单尺取 #include <stdio.h> #include ...
- HashSet源码分析2
package com.test1; import java.util.HashSet; import java.util.Iterator; import java.util.Set; public ...
- 未能找出类型或命名空间名称“T” 问题的解决方案
在已经引用“using System.Collections.Generic;”时,还是提示急未能找出类型或命名空间名称“T”的问题.
- mysql你确定掌握的那些sql语句
1.创建表 create table test(uid int not null,create_time timestamp default current_timestamp); 即:没有双引号,单 ...
- js获取上传的文件名称
<input name="file_" type="file" id="file_" size="100" /&g ...
- 我的arcgis培训照片7
来自:http://www.cioiot.com/successview-553-1.html
- 【转】Golang 关于通道 Chan 详解
原文:http://blog.csdn.net/netdxy/article/details/54564436 在用 chan 类型时,发生死锁的错误,表面上看不出什么问题 ------------- ...
- NA远程
远程网络按照L1分类: 租用专线(Leased Line):一般采用同步串行链路,使用HDLC/PPP封装: 线路交换(Circuit-Switched):一般采用异步串行链路,使用H ...
- js算法:分治法-循环赛事日程表
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- 本地调用jni之VC++无法导入问题
事实上非常easy,无法导入头文件就自己新建呗 1. 首先编写java代码 class Vrv { public native void printVersion(); static { System ...