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
相关推荐
92year20 分钟前
用Google ADK从零搭一个能调工具的AI Agent:Python实操全过程
python·ai·mcp
洛水水20 分钟前
【力扣100题】18.随机链表的复制
算法·leetcode·链表
woxihuan12345640 分钟前
SQL删除数据时存在依赖关系_设置外键级联删除ON DELETE
jvm·数据库·python
Jetev1 小时前
如何确定SQL字段是否为空_使用IS NULL与IS NOT NULL
jvm·数据库·python
蛐蛐蛐1 小时前
昇腾910B4上安装新版本CANN的正确流程
人工智能·python·昇腾
m0_702036532 小时前
mysql如何处理不走索引的OR查询_使用UNION ALL优化重写
jvm·数据库·python
2401_846339562 小时前
MySQL在云环境如何选择存储类型_SSD与高性能云盘配置建议
jvm·数据库·python
2601_957780842 小时前
Claude 4.6 对阵 GPT-5.4:2026 开发者大模型 API 选型深度解析
人工智能·python·gpt·ai·claude
2601_957780842 小时前
GPT-5.5 深度解析:2026年4月OpenAI旗舰模型的技术跨越与商业决策指南
大数据·人工智能·python·gpt·openai
zhaoyong2223 小时前
SQL如何统计每个用户的首次行为时间_MIN聚合与分组
jvm·数据库·python