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
相关推荐
学习星球8 分钟前
单调栈——从“找下一个更大的“到柱状图中的最大矩形
数据库·c++·算法·leetcode·xcode
————A24 分钟前
Agent 接收用户上传文件
人工智能·笔记·python·状态模式
可乐鸡翅yeah_27 分钟前
hls.js 内存泄漏实战排查,直播 M3U8 长时间播放异常定位方案
开发语言·javascript·python·django·ecmascript·m3u8·m3u8在线
可乐鸡翅yeah_33 分钟前
第三方接口对接 M3U8 流媒体排坑实战,解决外部服务商流兼容难题
前端·javascript·python·django·html·m3u8·m3u8在线
金融小师妹37 分钟前
多因子智能推演:黄金震荡回升,杰克逊霍尔“沃什首秀”政策如何重塑金价路径的AI预测框架
大数据·人工智能·python·线性回归
阿童木写作39 分钟前
跨马翻译:AI批量图片翻译与视频字幕翻译工具推荐
人工智能·python·音视频
阿kun要赚马内1 小时前
MCP(Model Context Protocol,模型上下文协议)
人工智能·python
来了就未晚1 小时前
Python基础 学习代码存储与命名规范
开发语言·python·学习
落魄大学生之流水线上谋生计2 小时前
LangGraph 基本用法指南
java·windows·python·langchain
华研前沿标杆游学2 小时前
宇树科技对外开放参访?机器人企业参访体验与行业核心价值解析
python