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
相关推荐
飞翔的佩奇1 小时前
【完整源码+数据集+部署教程】表盘指针检测系统源码和数据集:改进yolo11-CA-HSFPN
python·yolo·计算机视觉·数据集·yolo11·表盘指针检测
larance1 小时前
SQLAlchemy 的异步操作来批量保存对象列表
数据库·python
搏博2 小时前
基于Python3.10.6与jieba库的中文分词模型接口在Windows Server 2022上的实现与部署教程
windows·python·自然语言处理·flask·中文分词
lxmyzzs3 小时前
pyqt5无法显示opencv绘制文本和掩码信息
python·qt·opencv
萧鼎4 小时前
Python pyzmq 库详解:从入门到高性能分布式通信
开发语言·分布式·python
yujkss5 小时前
Python脚本每天爬取微博热搜-终版
开发语言·python
yzx9910135 小时前
小程序开发APP
开发语言·人工智能·python·yolo
飞翔的佩奇5 小时前
【完整源码+数据集+部署教程】二维码与查找模式检测系统源码和数据集:改进yolo11-CSwinTransformer
python·yolo·计算机视觉·数据集·yolo11·二维码与查找模式检测
圣保罗的大教堂5 小时前
leetcode 2348. 全 0 子数组的数目 中等
leetcode
大霞上仙5 小时前
实现自学习系统,输入excel文件,能学习后进行相应回答
python·学习·excel