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
相关推荐
Red丶哞13 分钟前
内网自建Postfix使用Python发送邮件
开发语言·python
rebekk22 分钟前
pytorch custom op的简单介绍
人工智能·pytorch·python
chushiyunen28 分钟前
uv使用笔记(python包的管理工具)
笔记·python·uv
曲幽28 分钟前
FastAPI状态共享秘籍:别再让中间件、依赖和路由“各自为政”了!
python·fastapi·web·request·state·depends·middleware
风清扬【coder】32 分钟前
Anaconda 被误删后抢救手册:数据恢复 + 环境重建应急流程
python·数据恢复·anaconda·环境重建
2401_8845632433 分钟前
进阶技巧与底层原理
jvm·数据库·python
2401_8732046533 分钟前
使用Pandas进行数据分析:从数据清洗到可视化
jvm·数据库·python
sheeta199833 分钟前
LeetCode 每日一题笔记 日期:2025.03.23 题目:1594.矩阵的最大非负积
笔记·leetcode·矩阵
l1t34 分钟前
DeepSeek 辅助编写python程序求解欧拉计划932题:2025数
开发语言·python·欧拉计划
灰色小旋风41 分钟前
力扣22 括号生成(C++)
开发语言·数据结构·c++·算法·leetcode