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
相关推荐
皓月斯语11 分钟前
B2118 验证子串
c++·题解
tqs_1234530 分钟前
Agent智能体+Skill插件引擎+Milvus混合检索 技术沉淀
java·python·milvus
Hi李耶43 分钟前
【LeetCode】4-寻找两个正序数组的中位数
算法·leetcode·职场和发展
眼泪划过的星空44 分钟前
LangChain 两大基础提示词模板:PromptTemplate 与 ChatPromptTemplate 详解
人工智能·python·langchain
狗都不学爬虫_1 小时前
AI逆向 - 99aq中心滑块验证+登录(wasm纯算)
爬虫·python·网络爬虫
天才测试猿1 小时前
实例介绍:Unittest框架及自动化测试实现流程
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
veminhe2 小时前
元数据索引有关的错
人工智能·python
一次旅行2 小时前
AutoAWQ完整实战:MIT激活感知AWQ量化,模型显存减半、推理提速且精度无损
人工智能·python·算法
ask_baidu2 小时前
python实现Doris的streamLoad
开发语言·python
GrowthDiary0072 小时前
算法题:寻找二维数组top k问题
数据结构·python·算法