Python | Leetcode Python题解之第335题路径交叉

题目:

题解:

python 复制代码
class Solution:
    def isSelfCrossing(self, distance: List[int]) -> bool:
        n = len(distance)

        # 处理第 1 种情况
        i = 0
        while i < n and (i < 2 or distance[i] > distance[i - 2]):
            i += 1

        if i == n:
            return False

        # 处理第 j 次移动的情况
        if ((i == 3 and distance[i] == distance[i - 2])
                or (i >= 4 and distance[i] >= distance[i - 2] - distance[i - 4])):
            distance[i - 1] -= distance[i - 3]
        i += 1

        # 处理第 2 种情况
        while i < n and distance[i] < distance[i - 2]:
            i += 1

        return i != n
相关推荐
Swizard12 小时前
别再让你的 Python 傻等了:三分钟带你通过 asyncio 实现性能起飞
python
前端小白在前进13 小时前
力扣刷题:在排序数组中查找元素的第一个和最后一个位置
数据结构·算法·leetcode
Darkershadow13 小时前
python学习之串口通信
python·学习
38242782714 小时前
python:输出JSON
前端·python·json
也许是_14 小时前
大模型应用技术之 详解 MCP 原理
人工智能·python
iAkuya15 小时前
(leetcode)力扣100 23反转链表(迭代||递归)
算法·leetcode·链表
沙漠豪15 小时前
提取PDF发票信息的Python脚本
开发语言·python·pdf
F_D_Z16 小时前
【Python】家庭用电数据的时序分析
python·数据分析·时序分析·序列分解
a程序小傲17 小时前
蚂蚁Java面试被问:注解的工作原理及如何自定义注解
java·开发语言·python·面试