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
相关推荐
吴佳浩5 小时前
Python入门指南(六) - 搭建你的第一个YOLO检测API
人工智能·后端·python
superman超哥6 小时前
仓颉语言中基本数据类型的深度剖析与工程实践
c语言·开发语言·python·算法·仓颉
Learner__Q7 小时前
每天五分钟:滑动窗口-LeetCode高频题解析_day3
python·算法·leetcode
————A7 小时前
强化学习----->轨迹、回报、折扣因子和回合
人工智能·python
阿昭L7 小时前
leetcode链表相交
算法·leetcode·链表
徐先生 @_@|||7 小时前
(Wheel 格式) Python 的标准分发格式的生成规则规范
开发语言·python
Mqh1807627 小时前
day45 简单CNN
python
学习者0078 小时前
python 下载离线库方法
python
声声codeGrandMaster8 小时前
AI之模型提升
人工智能·pytorch·python·算法·ai
魔镜前的帅比8 小时前
多 Agent 架构:Coordinator + Worker 模式
python·ai