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
相关推荐
做运维的阿瑞9 小时前
用 Python 构建稳健的数据分析流水线
开发语言·python·数据分析
左师佑图9 小时前
综合案例:Python 数据处理——从Excel文件到数据分析
开发语言·python·数据分析·excel·pandas
l1t10 小时前
利用DeepSeek修改数据结构提升求解集合程序效率
数据结构·python·deepseek
jiushun_suanli10 小时前
PyTorch CV模型实战全流程(一)
人工智能·pytorch·python
2301_7644413310 小时前
基于python构建的低温胁迫实验
开发语言·python
天才测试猿11 小时前
Selenium定位元素的方法css和xpath的区别
css·自动化测试·软件测试·python·selenium·测试工具·测试用例
云烟成雨TD11 小时前
NumPy 2.x 完全指南【四十二】线性代数之向量运算
python·机器学习·numpy
m0_7381207211 小时前
网络安全编程——开发一个TCP代理Python实现
python·tcp/ip·安全·web安全·网络安全
Dream it possible!12 小时前
LeetCode 面试经典 150_链表_旋转链表(64_61_C++_中等)
c++·leetcode·链表·面试