leetcode-mid-array-334 Increasing Triplet Subsequence-NO
mycode time limited
class Solution(object):
def increasingTriplet(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
length = len(nums)
temp = []
for i,num_i in enumerate(nums[:length-2]):
for j,num_j in enumerate(nums[i+1:length-1]):
if num_i < num_j:
for k in nums[i+j+2:]:
if k > nums[i+j+1]:
return True
return False
参考:
思路:不断更新最大值和最小值,如果elif遇见介于其中的,就可以返回True啦
注意:Python中可以用如下方式表示正负无穷:
float("inf"), float("-inf")
class Solution(object):
def increasingTriplet(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
min1 = min2 = float('inf')
for item in nums:
if item <= min1: #[1,1,-2,6] 如果只是<,那么min1=1,min2=1,错误
min1= item
elif item < min2:
min2 = item
elif item > min2: #不是else,否则会出现item=min2的情况
return True
return False
leetcode-mid-array-334 Increasing Triplet Subsequence-NO的更多相关文章
- 【LeetCode】334. Increasing Triplet Subsequence 解题报告(Python)
[LeetCode]334. Increasing Triplet Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode. ...
- [LeetCode] 334. Increasing Triplet Subsequence 递增三元子序列
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- 334. Increasing Triplet Subsequence(也可以使用dp动态规划)
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- 334. Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- 334. Increasing Triplet Subsequence My Submissions Question--Avota
问题描述: Given an unsorted array return whether an increasing subsequence of length 3 exists or not in ...
- 334 Increasing Triplet Subsequence 递增的三元子序列
给定一个未排序的数组,请判断这个数组中是否存在长度为3的递增的子序列.正式的数学表达如下: 如果存在这样的 i, j, k, 且满足 0 ≤ i < j < k ≤ n-1, ...
- 【LeetCode】Increasing Triplet Subsequence(334)
1. Description Given an unsorted array return whether an increasing subsequence of length 3 exists o ...
- [LeetCode] Increasing Triplet Subsequence 递增的三元子序列
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- Leetcode: Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- LeetCode——Increasing Triplet Subsequence
Question Given an unsorted array return whether an increasing subsequence of length 3 exists or not ...
随机推荐
- Java并发编程:锁的释放
Java并发编程:锁的释放 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839496;} Ja ...
- HDUSTOJ-1559 Vive la Difference!(简单题)
1559: Vive la Difference! 时间限制: 3 Sec 内存限制: 128 MB提交: 18 解决: 14[提交][状态][讨论版] 题目描述 Take any four po ...
- 通过编写串口助手工具学习MFC过程--(十一)弹出模态型对话框
通过编写串口助手工具学习MFC过程 因为以前也做过几次MFC的编程,每次都是项目完成时,MFC基本操作清楚了,但是过好长时间不再接触MFC的项目,再次做MFC的项目时,又要从头开始熟悉.这次通过做一个 ...
- [51Nod1850] 抽卡大赛
link $solution:$ 朴素 $dp$,暴力枚举选择 $i$ 号人的第 $j$ 张卡片,朴素 $dp$ 即可,时间复杂度 $O(n^4)$ . 考虑对于朴素 $dp$ 的优化,发现其实是一个 ...
- P2220 [HAOI2012]容易题
传送门 首先 $(\sum_{i=1}^{n}a_i)(\sum_{i=1}^{m}b_i)$ 展开以后包含了所有 $ab$ 两两相乘的情况并且每种组合只出现一次 发现展开后刚好和题目对序列价值的定义 ...
- String.Net “System.TypeInitializationException”类型的未经处理的异常在 Spring.NetDemo.exe 中发生
今天编写String.Net时,遇到“System.TypeInitializationException”类型的未经处理的异常在 Spring.NetDemo.exe 中发生 原因配置文件的顺序写错 ...
- 02-Django-views
# views 视图# 1. 视图概述- 视图即视图函数,接收web请求并返回web响应的事物处理函数.- 响应指符合http协议要求的任何内容,包括json,string, html等 # 2 其他 ...
- Python 自定义三方库
一.注册一个pypi账号 https://pypi.org/ 二.github上创建一个项目 https://github.com/ 三.编写自己的python项目 项目结构(参考):https:// ...
- python email模块
python email模块 官方文档 email模块 电子邮件包是一个用于管理电子邮件消息的库.它的特殊设计不用于向SMTP (RFC 2821).NNTP或其他服务器发送任何电子邮件消息;这些是模 ...
- linux 建立 MySQL 账号
以 root 身份登录 Linux 系统,创建 mysql 组和用户 [root@Nagios-Server ~]# groupadd mysql [root@Nagios-Server ~]# us ...