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
相关推荐
The_Second_Coming10 分钟前
Python 学习笔记:基础篇
运维·笔记·python·学习
诗句藏于尽头10 分钟前
python实战学习记录
python·学习
AI松子66629 分钟前
PyTorch-混合精度训练(amp)
人工智能·pytorch·python
MDLZH29 分钟前
Pytorch性能调优简单总结
人工智能·pytorch·python
程序员爱钓鱼1 小时前
Python 编程实战 · 实用工具与库 — Flask 路由与模板
前端·后端·python
程序员爱钓鱼1 小时前
Python 编程实战 · 实用工具与库 — Django 项目结构简介
后端·python·面试
新之助小锅2 小时前
java版连接汇川PLC,发送数据,读取数据,保持重新链接,适用安卓
android·java·python
海琴烟Sunshine2 小时前
leetcode 383. 赎金信 python
python·算法·leetcode
惊讶的猫8 小时前
LSTM论文解读
开发语言·python
cynicme9 小时前
力扣3228——将 1 移动到末尾的最大操作次数
算法·leetcode