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的更多相关文章

  1. 【LeetCode】334. Increasing Triplet Subsequence 解题报告(Python)

    [LeetCode]334. Increasing Triplet Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode. ...

  2. [LeetCode] 334. Increasing Triplet Subsequence 递增三元子序列

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  3. 334. Increasing Triplet Subsequence(也可以使用dp动态规划)

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  4. 334. Increasing Triplet Subsequence

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  5. 334. Increasing Triplet Subsequence My Submissions Question--Avota

    问题描述: Given an unsorted array return whether an increasing subsequence of length 3 exists or not in ...

  6. 334 Increasing Triplet Subsequence 递增的三元子序列

    给定一个未排序的数组,请判断这个数组中是否存在长度为3的递增的子序列.正式的数学表达如下:    如果存在这样的 i, j, k,  且满足 0 ≤ i < j < k ≤ n-1,    ...

  7. 【LeetCode】Increasing Triplet Subsequence(334)

    1. Description Given an unsorted array return whether an increasing subsequence of length 3 exists o ...

  8. [LeetCode] Increasing Triplet Subsequence 递增的三元子序列

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  9. Leetcode: Increasing Triplet Subsequence

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  10. LeetCode——Increasing Triplet Subsequence

    Question Given an unsorted array return whether an increasing subsequence of length 3 exists or not ...

随机推荐

  1. [LeetCode] 65. 有效数字

    题目链接 : https://leetcode-cn.com/problems/valid-number/ 题目描述: 验证给定的字符串是否可以解释为十进制数字. 例如: "0"` ...

  2. 搜索专题: HDU1372Knight Moves

    Knight Moves Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  3. Vue-Quill-Editor 富文本编辑器

    通俗来说:富文本,就是比较丰富的文本编辑器.普通的框只能输入文字,而富文本还能给文字加颜色样式等. 富文本编辑器有很多,例如:KindEditor.Ueditor.但并不原生支持vue 但是我们今天要 ...

  4. php设置错误级别

    ini_set('display_errors', 1); error_reporting(E_ALL);

  5. python之路之——操作系统的发展历史

    阅读目录 手工操作 —— 穿孔卡片 批处理 —— 磁带存储和批处理系统 多道程序系统 分时系统 实时系统 通用操作系统 操作系统的进一步发展 操作系统的作用 手工操作 —— 穿孔卡片 1946年第一台 ...

  6. LOCK - 明确地锁定一个表

    SYNOPSIS LOCK [ TABLE ] name [, ...] [ IN lockmode MODE ] where lockmode is one of: ACCESS SHARE | R ...

  7. Linux--shell函数--08

    1.函数介绍 为了避免代码的重复使用,我们一般通过函数编写代码块,而这一个代码块用来实现某种功能:且这个功能在后面的代码中会重复使用. 2.函数的语法格式: [ function ] 函数名 [ ( ...

  8. MyBatis源码浅析

    什么是MyBatis MyBatis是支持定制化SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手工设置参数以及抽取结果集.MyBatis 使用简单的 ...

  9. 10年前文章_eclipse下perl环境搭建

    eclipse下perl环境搭建1.Eclipse下安装perl插件Help -Software Updates…- Available .- Add Site… :http://e-p-i-c ...

  10. GUI学习之十六——QSpinBox学习总结

    我们在上一章讲了步长调节器QAbstractSpinBox,这一节来讲一下它的一个子类:QSpinBox 一.描述 QSpinBox是一个主要处理整数和离散值集合的步长调节器控件,它允许用户通过单击增 ...