388. Longest Absolute File Path
来源:互联网 发布:jquery json 查找 编辑:程序博客网 时间:2024/05/17 07:58
提交了三次才AC,==为啥这种题目老是各种错误,都没有想到。
- 感觉只要在由i++的地方,都要判断一下是不是会超范围。
- 只要有更新sum的地方都要更新最大值。
class Solution {public: int lengthLongestPath(string input) { int maxSum=0; int sum=0; stack<int> nums; stack<int> depth; int i=0; string temp; while(i<input.size()&&input[i]!='\n') temp+=input[i++]; nums.push(temp.length()); sum+=temp.length(); depth.push(0); if(temp.find('.')!=std::string::npos) maxSum=max(maxSum,sum); while(i<input.size()) { int depthTemp=0; while(input[++i]=='\t') depthTemp++; string temp; while(i<input.size()&&input[i]!='\n') temp+=input[i++]; //cout<<temp<<endl; while((!depth.empty())&&depthTemp<=depth.top()) { sum-=nums.top(); nums.pop(); depth.pop(); } depth.push(depthTemp); nums.push(temp.length()+(depthTemp!=0)); sum+=nums.top(); if(temp.find('.')!=std::string::npos) maxSum=max(maxSum,sum); } return maxSum; }};
0 0
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- Longest Absolute File Path
- Longest Absolute File Path
- LeetCode—388. Longest Absolute File Path
- LeetCode—388. Longest Absolute File Path
- leetcode -- 388. Longest Absolute File Path
- 388. [LeetCode]Longest Absolute File Path
- [Leetcode]388. Longest Absolute File Path
- 【LeetCode】 388. Longest Absolute File Path
- C++实验二+简单程序的编写
- spring事务属性详解
- struts2创建Action的三种方式
- C++练习:递归输出vector
- 搭建一个spring-boot项目 1
- 388. Longest Absolute File Path
- 5-14 电话聊天狂人 (25分)
- 神经网络中的激活函数(activation function)-Sigmoid, ReLu, TanHyperbolic(tanh), softmax, softplus
- EXT4文件系统的代码实现-磁盘格式
- 3-8 Python中浮点数和布尔型
- Problem D: 平面上的点——Point类 (I)
- 超链接和锚点
- POJ 2658 Song G++
- Groovy脚本学习