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
相关推荐
老鼠只爱大米4 分钟前
LeetCode算法题详解 15:三数之和
算法·leetcode·双指针·三数之和·分治法·three sum
Amelia1111116 分钟前
day48
python
小北方城市网9 分钟前
第 6 课:云原生架构终极落地|K8s 全栈编排与高可用架构设计实战
大数据·人工智能·python·云原生·架构·kubernetes·geo
智航GIS12 分钟前
10.1 网站防爬与伪装策略
python
菜鸟233号19 分钟前
力扣416 分割等和子串 java实现
java·数据结构·算法·leetcode
belldeep19 分钟前
python:pyTorch 入门教程
pytorch·python·ai·torch
YJlio21 分钟前
Registry Usage (RU) 学习笔记(15.5):注册表内存占用体检与 Hive 体量分析
服务器·windows·笔记·python·学习·tcp/ip·django
奔波霸的伶俐虫22 分钟前
redisTemplate.opsForList()里面方法怎么用
java·开发语言·数据库·python·sql
Swift社区25 分钟前
LeetCode 469 凸多边形
算法·leetcode·职场和发展
圣保罗的大教堂28 分钟前
leetcode 1458. 两个子序列的最大点积 困难
leetcode