Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.
Formally the function should:
Return true if there exists i, j, k
such that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false.
Your algorithm should run in O(n) time complexity and O(1) space complexity.
Examples:
Given [1, 2, 3, 4, 5]
,
return true
.
Given [5, 4, 3, 2, 1]
,
return false
.
public class Solution {
public boolean increasingTriplet(int[] nums) {
if (nums == null || nums.length < ) return false; int m1 = Integer.MAX_VALUE, m2 = Integer.MAX_VALUE;
for (int a : nums) {
if (m1 >= a) m1 = a;
else if (m2 >= a) m2 = a;
else return true;
}
return false;
}
}
Increasing Triplet Subsequence的更多相关文章
- 【LeetCode】334. Increasing Triplet Subsequence 解题报告(Python)
[LeetCode]334. Increasing Triplet Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode. ...
- [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(334)
1. Description Given an unsorted array return whether an increasing subsequence of length 3 exists o ...
- LeetCode-334. Increasing Triplet Subsequence
Description: Given an unsorted array return whether an increasing subsequence of length 3 exists or ...
- Leetcode: 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
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 ...
- [Swift]LeetCode334. 递增的三元子序列 | 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 ...
随机推荐
- centos 7.0 nginx 1.7.9 安装过程
系统用的是centos 7.0最小化安装 我现在安装完了 写一下步骤 还没完全搞懂 首先安装GCC [root@localhost ~]# yum install -y gcc gcc-c++ 已加载 ...
- tamper绕WAF详解
0x00 背景 sqlmap中的tamper脚本来对目标进行更高效的攻击. 由于乌云知识库少了sqlmap-tamper 收集一下,方便学习. 根据sqlmap中的tamper脚本可以学习过绕过一些技 ...
- java在继承中父类的成员变量是否会被子类所覆盖
假如 父类 int num =7:子类 int num =9:父类是否会被子类所覆盖? 给你看两个例子: 第一个例子: 第二个例子: 这两个例子的区别只有一句话 由此证明了子类从父类继承的时候 ...
- 网上搜的一个shell中 中文设置的一个样例;
from:http://www.cnblogs.com/52linux/archive/2012/03/24/2415082.html SSH Secure Shell Client中文乱码的解决方法 ...
- linux环境下给文件加密/解密的方法
原文地址:linix环境下给文件加密/解密的方法 作者:oracunix 一. 利用 vim/vi 加密:优点:加密后,如果不知道密码,就看不到明文,包括root用户也看不了:缺点:很明显让别人知 ...
- CF461B Appleman and Tree (树DP)
CF462D Codeforces Round #263 (Div. 2) D Codeforces Round #263 (Div. 1) B B. Appleman and Tree time l ...
- 【转载】VC维的来龙去脉
本文转载自 火光摇曳 原文链接:VC维的来龙去脉 目录: 说说历史 Hoeffding不等式 Connection to Learning 学习可行的两个核心条件 Effective Number o ...
- springmvc 数据精准绑定
因为使用dwz 的lookup功能,回调的值通过name以 xxx.xxValue 来自动得到,而我还有些表单数据的name是没有前缀的, 到springmvc后台绑定的的话默认的绑定是有问题的.这是 ...
- 修改dedecms默认文章来源 "未知"改为关键词
在dedecms后台发表文章时文章来源是可选的,有时我们没有选择或没填写,那么前台默认文章来源即“未知”.如何将dedecms默认文章来源改为自己想要的关键词呢?即将“未知”改为“keyword”呢? ...
- 分解大质数模板(复杂度小于sqrt(n))
//POJ 1811 #include <cstdio> #include <cstring> #include <algorithm> #include < ...