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
相关推荐
计算机学姐几秒前
基于Python的B站数据分析及可视化系统【2026最新】
开发语言·vue.js·python·信息可视化·数据挖掘·数据分析·推荐算法
haiyu_y1 分钟前
Day 33 类的装饰器
python
轻竹办公PPT8 分钟前
AI自动写年终总结PPT
人工智能·python·powerpoint
pursuit_csdn12 分钟前
力扣周赛 - 479
算法·leetcode·职场和发展
程序员小远24 分钟前
Web自动化测试详解
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
红石程序员31 分钟前
Python环境管理
开发语言·python
Chennnng33 分钟前
关于python版本,显卡版本,torch版本之间的问题
开发语言·python
战南诚1 小时前
python序列化-dumps的妙用
python
华研前沿标杆游学1 小时前
12月13日·东莞线下沙龙|少年企业家商业思维拓展营
python
学学学无无止境1 小时前
力扣-从前序与中序遍历序列构造二叉树
leetcode