Python | Leetcode Python Problem Solver #456 132 Pattern-Problem Solving:
最编程
2024-10-09 07:13:56
...
class Solution:
def find132pattern(self, nums: List[int]) -> bool:
candidate_i, candidate_j = [-nums[0]], [-nums[0]]
for v in nums[1:]:
idx_i = bisect.bisect_right(candidate_i, -v)
idx_j = bisect.bisect_left(candidate_j, -v)
if idx_i < idx_j:
return True
if v < -candidate_i[-1]:
candidate_i.append(-v)
candidate_j.append(-v)
elif v > -candidate_j[-1]:
last_i = -candidate_i[-1]
while candidate_j and v > -candidate_j[-1]:
candidate_i.pop()
candidate_j.pop()
candidate_i.append(-last_i)
candidate_j.append(-v)
return False
上一篇: LC538 - 将二叉搜索树转换为累积树-2 个想法
下一篇: Python-Numpy
推荐阅读
-
python 机器人编程 - 使用 python API 调用控制 wifi 小车的示例程序
-
LeetCode:计算满足 k 约束 I 的子串数量(滑动窗口 Java)
-
Python 教程:Python 中的集合及其对集合的所有操作
-
模块编译成功,但 python 运行时找不到依赖项 名称为''的模块
-
Python 编程:常用模块分类组织
-
Python -- 爬虫小说学习 -- 仅供个人娱乐 -- III.
-
每日 Python 工具包 [Celery]。
-
LeetCode] 动态编程 - 95.动态编程 - 95.不同的二叉搜索树 II(附完整 Python/C++ 代码) - 基本思想
-
基于卷积神经网络、resnet50、mobilenet 模型的蔬菜识别系统 [pytorch 框架+python 源代码
-
屏幕录制功能的 Python 实现