要求寻找的是最长的长度的,那么考虑文件夹和文件的存在的不同形式的,利用当前所存在的层数和对应的长度之间做一个映射关系的并且用于计算总的长度关系的。

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的更多相关文章

  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】388. Longest Absolute File Path 解题报告(Python)

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

  3. 【leetcode】388. Longest Absolute File Path

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

  4. 388. Longest Absolute File Path

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

  5. 388 Longest Absolute File Path 最长的绝对文件路径

    详见:https://leetcode.com/problems/longest-absolute-file-path/description/ C++: class Solution { publi ...

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

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

  7. Leetcode: Longest Absolute File Path

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

  8. Leetcode算法比赛----Longest Absolute File Path

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

  9. Longest Absolute File Path -- LeetCode

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

随机推荐

  1. 【题解】Luogu P2153 [SDOI2009]晨跑

    原题传送门 一眼应该就能看出是费用流 因为每个交叉路口只能通过一次,所以我们进行拆点,连一条流量为1费用为0的边 再按照题目给的边(是单向边)建图 跑一下MCMF就行了 拆点很套路的~ #includ ...

  2. UI自动化(十一)selenium框架

    框架(提供一个好的解决方案给其他人用) webUi自动化框架 弊端:代码维护难,定位问题复杂,稳定性 PageObject分层:将一个页面抽象成一个类,将这个页面下的可操作性的功能点,当做这个类下的函 ...

  3. Spring Boot 数据库连接池 Druid

    简介 数据库连接是一种关键的有限的昂贵的资源,这一点在多用户的网页应用程序中体现得尤为突出.对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库连接池正是针对这个问 ...

  4. WEB 前端插件整理

    Vs Code 系统插件 #1 Bracket Pair Colorizer 让括号拥有独立的颜色,易于区分.可以配合任意主题使用. #2 Code Runner 非常强大的一款插件,能够运行多种语言 ...

  5. Sql语句中IN和exists的区别及应用

    表展示 首先,查询中涉及到的两个表,一个user和一个order表,具体表的内容如下: user表: order表: in 确定给定的值是否与子查询或列表中的值相匹配.in在查询的时候,首先查询子查询 ...

  6. 一小时学会 C# 6.0

    一.字符串插值 (String Interpolation) C# 6之前我们拼接字符串时需要这样 var Name = "Jack"; var results = "H ...

  7. 使用flask搭建服务端

    ---恢复内容开始--- 本文默认采用python3 一.虚拟环境 创建环境 mkdir myproject cd myproject python3 -m venv venv //Windows平台 ...

  8. eclipse安装插件配置Android开发环境

    安卓版本与sdk的对应   转载自: https://blog.csdn.net/cx776474961/article/details/79501740 最近学习Android开发,电脑已有开发we ...

  9. IdentityServer4服务器配置

    Session认证和JWT(Json Web Token) Token认证就是基于JWT 1.Session认证 1. 用户输入其登录信息 2. 服务器验证信息是否正确,并创建一个session,然后 ...

  10. java笔记 -- java运算

    运算符: 算术运算符: 加减乘除求余 + , - , * , / , % 当参与/运算的两个操作数都是整数时, 表示整数除法, 否则表示浮点除法. 例: 15 / 2 = 7; 15 % 2 = 1; ...