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
相关推荐
李昊哲小课1 小时前
Python办公自动化教程 - 第7章 综合实战案例 - 企业销售管理系统
开发语言·python·数据分析·excel·数据可视化·openpyxl
不知名的老吴1 小时前
返回None还是空集合?防御式编程的关键细节
开发语言·python
李昊哲小课2 小时前
Python办公自动化教程 - 第5章 图表创建 - 让数据可视化
python·信息可视化·数据分析·数据可视化·openpyxl
chushiyunen2 小时前
python pygame实现贪食蛇
开发语言·python·pygame
Dream of maid2 小时前
Python-基础2(流程控制)
python
Lenyiin3 小时前
《Python 修炼全景指南:一》从环境搭建到第一个程序
开发语言·python
6Hzlia3 小时前
【Hot 100 刷题计划】 LeetCode 42. 接雨水 | C++ 动态规划与双指针题解
c++·算法·leetcode
涛声依旧393163 小时前
Python项目实战:学生信息管理系统
开发语言·python·数据挖掘
kcuwu.4 小时前
Python进阶:生成器与协程,高效并发编程的核心实践
windows·python·php
XiaoQiao6669994 小时前
python 简单题目练手【详解版】【1】
开发语言·python