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
相关推荐
JaydenAI9 小时前
[LangChain之链]LangChain的Chain——由Runnable构建的管道
python·langchain
kali-Myon9 小时前
2025春秋杯网络安全联赛冬季赛-day3
python·安全·web安全·ai·php·web·ctf
AbsoluteLogic9 小时前
Python——彻底明白Super() 该如何使用
python
小猪咪piggy9 小时前
【Python】(4) 列表和元组
开发语言·python
@––––––9 小时前
力扣hot100—系列4-贪心算法
算法·leetcode·贪心算法
墨理学AI9 小时前
一文学会一点python数据分析-小白原地进阶(mysql 安装 - mysql - python 数据分析 - 学习阶段梳理)
python·mysql·数据分析
数研小生9 小时前
亚马逊商品列表API详解
前端·数据库·python·pandas
独好紫罗兰9 小时前
对python的再认识-基于数据结构进行-a005-元组-CRUD
开发语言·数据结构·python
jianghua00110 小时前
Python中的简单爬虫
爬虫·python·信息可视化
喵手10 小时前
Python爬虫实战:针对Python官网,精准提取出每一个历史版本的版本号、发布日期以及对应的文档/详情页链接等信息,并最终清洗为标准化的CSV文件!
爬虫·python·爬虫实战·零基础python爬虫教学·python官方数据采集·采集历史版本版本号等信息·导出csv文件