334. Increasing Triplet Subsequence
来源:互联网 发布:android无源码调试器 编辑:程序博客网 时间:2024/05/22 15:44
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
.
Credits:
Special thanks to @DjangoUnchained for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
public class Solution { public boolean increasingTriplet(int[] nums) { if(nums.length<3)return false; int least = Integer.MAX_VALUE; int media = Integer.MAX_VALUE; int i = 0; while(i<nums.length){ if(nums[i]<=least){ least = nums[i]; }else if(nums[i]<=media){ media=nums[i]; }else return true; i++; } return false; }}
0 0
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- 334. Increasing Triplet Subsequence
- dede整合discuz后完美实现双向同步登入登出解决方案
- Column ‘nature’ has duplicated value ‘婆婆妈妈’ in SET
- CentOS本地yum源
- 在DEDECMS后台管理文档列表中,需要在列表中显示自定义的字段内容
- 嵌入的flash遮挡弹出div层解决方法
- 334. Increasing Triplet Subsequence
- 【转载】解决弹出层被Flash及select挡住的问题
- 楼层住宅选第几层,教你五步选出最佳楼层
- 自定义鼠标选择文本颜色背景等
- 网页加载进度条。
- 鼠标经过图片亮度改变
- 同学结婚不想去怎么办啊?
- gitbash使用
- DEDE栏目名称长度 修改