leetcode 388.Lonest Absolute File Path
要求寻找的是最长的长度的,那么考虑文件夹和文件的存在的不同形式的,利用当前所存在的层数和对应的长度之间做一个映射关系的并且用于计算总的长度关系的。
class Solution {
public:
int lengthLongestPath(string input) {
int res=,level=;
map<int,int> m{{,}};
int n=input.size();
for(int i=;i<n;i++){
int start=i;
while(i<n && input[i]!='\n'&&input[i]!='\t') i++;
if(i>=n || input[i]=='\n'){
string temp=input.substr(start,i-start);
if(temp.find('.')!=string::npos){
res=max(res,m[level]+(int)temp.size());
}else{
level++;
m[level]=m[level-]+(int)temp.size()+;
}
level=;
}
else{
level++;
}
}
return res;
}
};
leetcode 388.Lonest 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】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表示层数. 思路是如果当前层数多余已经有的 ...
- 388 Longest Absolute File Path 最长的绝对文件路径
详见:https://leetcode.com/problems/longest-absolute-file-path/description/ C++: class Solution { publi ...
- [LeetCode] 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算法比赛----Longest Absolute File Path
问题描述 Suppose we abstract our file system by a string in the following manner: The string "dir\n ...
- Longest Absolute File Path -- LeetCode
Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...
随机推荐
- Spring 学习——Spring AOP——AOP概念篇
AOP AOP的定义:AOP,Aspect Oriented Programming的缩写,意为面向切面编程,是通过预编译或运行期动态代理实现程序功能处理的统一维护的一种技术 实现方式 预编译 Asp ...
- Bootstrap3基础 table-striped 表格实现隔行换色(浅灰色与白色交替)
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- 09.vue中样式-style
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- OLAP多维数据库备份
本人开发了一款OLAP多维数据库备份软件,现将其贡献博客园. 链接: https://pan.baidu.com/s/1oL8xVZfSUiUcvrvohxKVoQ 提取码: nmh5 操作方式: 1 ...
- 短路运算符(逻辑与&& 和 逻辑或||)
首先我们来解释一下短路运算符: 短路运算符就是从左到右的运算中前者满足要求,就不再执行后者了: 可以理解为: &&为取假运算,从左到右依次判断,如果遇到一个假值,就返回假值,以后不再执 ...
- http随笔
1.什么是http? HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从WWW服务器传输超文本到本地浏览器的传送协议.它可以使浏览器更加高效,使网 ...
- guxh的python笔记七:抽象基类
1,鸭子类型和白鹅类型 1.1,白鹅类型 白鹅类型对接口有明确定义,比如不可变序列(Sequence),需要实现__contains__,__iter__,__len__,__getitem__,__ ...
- Luffy之课程详情页
Luffy之课程详情页 提前写好课程详情的template,并放入到Vue中 注册路由 import CourseDetail from "../components/CourseDetai ...
- JS中输出EL表达式
要在javascript中使用El表达式,需要在el表达式两端加上单引号或者双引号 <script type="text/javascript"> jQuery(doc ...
- js 里面的那些节省字节的写法 a|0 void 0等等
//取整 parseInt(a,10); Math.floor(a); ~~a; //节省之后的写法 a|0; //节省之后的写法 //四舍五入 Math.round(a); a+.5|0; //节省 ...