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 ...
随机推荐
- .NET Framework源码查看及下载
一.资源 1.http://referencesource.microsoft.com/ 二.备注 1.可在线预览.Net Framework 4.6.1源码实现
- 【转】Flume日志收集
from:http://www.cnblogs.com/oubo/archive/2012/05/25/2517751.html Flume日志收集 一.Flume介绍 Flume是一个分布式.可 ...
- 使用MVVM框架avalon.js实现一个简易日历
最近在做公司内部的运营管理系统,因为与日历密切相关,同时无需触发条件直接显示在页面上,所以针对这样的功能场景,我就用avalon快速实现了一个简易日历,毕竟也是第一次造日历这种轮子,所以这里记录下我当 ...
- netstat命令的常见用法(转)
netstat 的10个基本用法 Netstat 简介 Netstat 是一款命令行工具,可用于列出系统上所有的网络套接字连接情况,包括 tcp, udp 以及 unix 套接字,另外它还能列出处于监 ...
- js操作json与字符串相互转换
字符串转对象(strJSON代表json字符串) var obj = eval(strJSON); var obj = strJSON.parseJSON(); var obj = JSON.pars ...
- Redis安装和使用
新年伊始,万象更新.祝大家:新的一年,工作顺利,生活越来越美好. http://www.redis.cn/commands.html http://try.redis.io/ http://www.c ...
- 兼容ie的jquery ajax文件上传
Ajax文件上传插件很多,但兼容性各不一样,许多是对ie不兼容的,另外项目中是要求将网页内容嵌入到桌面端应用的,这样就不允许带flash的上传插件了,如:jquery uploadify...悲剧 对 ...
- 【codevs1163】访问艺术馆
题目描述 皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画.艺术馆的结构,每条走廊要么分叉为二条走廊,要么通向一个展览室.皮尔知道每个展室里藏画的数量,并且他精确地测量了通过每条走廊的 ...
- JSP自定义标签之Hello Costom tag小例子
1.项目结构 2.实现自定义tag所需依赖 <dependency> <groupId>javax.servlet</groupId> <artifactId ...
- maven之respository(仓库)本地路径修改
maven默认的仓库路径会在c盘(我的C:\Users\Administrator\.m2\repository),这样如果系统出问题或其他原因会造成仓库损坏,因此会自己配置仓库路径. 1.首先找到你 ...