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 ...
随机推荐
- weex安装失败,按照官网步骤多次失败后成功
在安装Weex Toolkit之前,需要确保安装了node, npm. yangfeifei:~ yff$ node -v v6.10.2 yangfeifei:~ yff$ npm -v 3.10. ...
- cpu使用率低负载高,原因分析
原因总结 产生的原因一句话总结就是:等待磁盘I/O完成的进程过多,导致进程队列长度过大,但是cpu运行的进程却很少,这样就体现到负载过大了,cpu使用率低. 下面内容是具体的原理分析:在分析负载为什么 ...
- String.split()与StringUtils.split()
我们平时进行简单的字符串分割的时候,尽量不要用String自身的split方法,它是匹配正则表达式的,如果遇到$这种特殊字符,需要转义一下.用StringUtils.split()方法会更方便 使用a ...
- [C++ Primer Plus] 零散知识点(一)、输入函数(cin,cin.get,cin.getline等)+string头文件辨析
本文几乎照搬http://www.cnblogs.com/luolizhi/p/5746775.html博客,只修改了一点点.不知道怎么转发过来,尴尬... 学C++的时候,这几个输入函数弄的有点迷糊 ...
- AjaxPro对象参数传递
1.客户端配置 2.服务端注册,配置 对象参数用到的方法 3.Web.config文件配置 需要注意的是ajax以及ajaxpro调用的方法必须是静态方法,如果存在非静态方法可以从页面作为参数传递
- RPM Yum 相关命令及参数
RPM 命令 我们可以直接使用rpm命令,对软件包进行一些操作. 安装 rpm –ivh <package_name> rpm –Uvh <package_name> # 没有 ...
- Java 爬虫学习
Java爬虫领域最强大的框架是JSoup:可直接解析具体的URL地址(即解析对应的HTML),提供了一套强大的API,包括可以通过DOM.CSS选择器,即类似jQuery方式来取出和操作数据.主要功能 ...
- [福建集训2011][LOJ10111]相框
这题主要还是分类讨论欧拉回路 首先对于导线一端没有东西的新建一个节点 由于原图不一定连通所以需要用到并查集判断有多少个连通块 将一条导线连接的两个焊点连接 然后先对于只有一个连通块考虑 1.如果一个焊 ...
- Redis入门指南之三(入门)
本节主要介绍Redis的5种数据类型,同时使用Python API来操作Redis,其中python版本为3.5, redis版本为4.0.2. redis-py 的API的使用可以分类为: (1)连 ...
- (转)决定系数R2
有些讲得太烂了,我来通俗的梳理一下R2. Calculating R-squared 在线性回归的模型下,我们可以计算SE(line), SE(y均值). The statistic R2descri ...