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
相关推荐
飞Link几秒前
LangGraph SDK 全量技术手册:分布式 Agent 集群的远程调用与编排引擎
开发语言·分布式·python·数据挖掘
迷藏4941 分钟前
**基于Python与OpenCV的光场显示图像处理技术实践**在现代显示技术发展中,**光场显示(Light
java·图像处理·python·opencv
枫叶林FYL3 分钟前
【Python高级工程与架构实战】项目六:RAG知识库问答系统(企业文档智能)
python·深度学习·机器学习
witAI7 分钟前
gpt写小说工具2025推荐,助力高效创作小说
人工智能·python·gpt
Roselind_Yi8 分钟前
【开源仓库系列学习分享】MemPalace 仓库(超级记忆管家)全流程部署!(专业版)
人工智能·经验分享·笔记·python·数据挖掘·github·知识图谱
Flying pigs~~10 分钟前
检索增强生成RAG项目tools_04:flask➕fastapi➕高并发
数据库·python·flask·大模型·fastapi·异步
JACK的服务器笔记12 分钟前
《服务器测试百日学习计划——Day19:PCIe自动检测脚本,用Python把lspci设备清点标准化》
服务器·python·学习
吃着火锅x唱着歌15 分钟前
LeetCode 1963 使字符串平衡的最小交换次数
算法·leetcode·职场和发展
YJlio16 分钟前
Sysinternals实战教程专栏介绍:这不是一本到此为止的书,而是一套看穿 Windows 的排障方法
windows·python·电脑·outlook·windows部署·eixv3·pe装机
好运的阿财18 分钟前
OpenClaw工具拆解之 sessions_list+sessions_history
人工智能·python·程序人生·ai·ai编程·openclaw