Python | Leetcode Python题解之第388题文件的最长绝对路径

题目:

题解:

python 复制代码
class Solution:
    def lengthLongestPath(self, input: str) -> int:
        ans, i, n = 0, 0, len(input)
        level = [0] * (n + 1)
        while i < n:
            # 检测当前文件的深度
            depth = 1
            while i < n and input[i] == '\t':
                depth += 1
                i += 1

            # 统计当前文件名的长度
            length, isFile = 0, False
            while i < n and input[i] != '\n':
                if input[i] == '.':
                    isFile = True
                length += 1
                i += 1
            i += 1  # 跳过换行符

            if depth > 1:
                length += level[depth - 1] + 1
            if isFile:
                ans = max(ans, length)
            else:
                level[depth] = length
        return ans
相关推荐
飞猪~8 分钟前
LangChain python 版本 第一集
开发语言·python·langchain
2601_956319881 小时前
最新AI量化提效,先做可验证的小流程
人工智能·python
开飞机的舒克_2 小时前
FastAPI 实战入门:从路由、参数校验到依赖注入的后端开发指南
python·fastapi
霸道流氓气质2 小时前
Kiro 中反编译 JAR 包并分析字节码的流程指南
chrome·python·jar
人工智能时代 准备好了吗3 小时前
AI回答内容进入率监测:引用识别、文本匹配与语义判断
开发语言·人工智能·python
Frostnova丶3 小时前
(12)LeetCode 76. 最小覆盖子串
算法·leetcode·职场和发展
Metaphor6923 小时前
使用 Python 冻结 Excel 文件中的行、列和单元格
开发语言·python·excel
言乐64 小时前
Python实现建造微服务商城后台
开发语言·python·算法·微服务·架构
fenglllle4 小时前
chromadb emmbedding 向量检索
人工智能·python·embedding
wabs6664 小时前
关于动态规划【力扣583.两个字符串的删除操作的思考】
算法·leetcode·动态规划