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
相关推荐
DP+GISer1 分钟前
00基于pytorch的深度学习遥感地物分类全流程实战教程(包含遥感深度学习数据集制作与大图预测)-前言
pytorch·python·深度学习·图像分割·遥感·地物分类
耶夫斯计9 分钟前
【SQL_agent】基于LLM实现sql助理
数据库·python·sql·语言模型
vibag10 分钟前
RAG向量数据库
python·语言模型·langchain·大模型
梭七y10 分钟前
【力扣hot100题】(121)反转链表
算法·leetcode·链表
kisshuan1239610 分钟前
基于YOLO11改进的C3k2-AdditiveBlock实现命中检测与双重命中事件识别_1
python
mg66811 分钟前
0基础开发学习python工具_____用 Python + Pygame 打造绚丽烟花秀 轻松上手体验
开发语言·python·学习·pygame
nervermore99021 分钟前
2.6 测试
python
AD钙奶-lalala27 分钟前
leetcode核心母题总结
算法·leetcode·职场和发展
EZ_Python29 分钟前
告别WPS会员!用Python自制电子发票批量打印排版工具
python·自动化
写文章的大米30 分钟前
1 分钟读懂:Python 装饰器
python