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.length<3)
return false; for(int i=nums.length-1;i>=2;i--)
{
int j=i-1;
for( ;j>=1;j--)
{
if(nums[i]>nums[j])
{
int k=j-1;
for(;k>=0;k--)
{
if(nums[j]>nums[k])
return true;
}
} } }
return false;
}
}

334. Increasing Triplet Subsequence的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. 【LeetCode】Increasing Triplet Subsequence(334)

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

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

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

  8. Increasing Triplet Subsequence

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

  9. LeetCode-334. Increasing Triplet Subsequence

    Description: Given an unsorted array return whether an increasing subsequence of length 3 exists or ...

随机推荐

  1. Halcon 10.0:Hobject图像转CBitmap

    void HImage2CBitmap(Hobject pImage,CBitmap *wImage) { char lpcsType[MAX_STRING]; Hlong lPointer,widt ...

  2. g++默认支持c++11标准的办法

    //第一种,直接包含在源程序文件中,如第一行代码所示 #pragma GCC diagnostic error "-std=c++11" #include <iostream ...

  3. 佳佳的魔法药水 (vijos 1285)

    题目大意: 给出N种药水的价格,然后给出一些形如A B C 的关系,表示 A药水+B药水 可以组合出 C药水(保证 A+B 不会得到多种药水). 要求得到1号药水的最少花费和相应的方案数. N< ...

  4. web api同源策略

    1.重写JsonMediaTypeFormatter public class JsonpMediaTypeFormatter : JsonMediaTypeFormatter { private s ...

  5. Jquery easyui datagrid 导出Excel

    From:http://www.cnblogs.com/weiqt/articles/4022399.html datagrid的扩展方法,用于将当前的数据生成excel需要的内容. 1 <sc ...

  6. HDU 3336 扩展kmp

    题目大意: 找到字符串中所有和前缀字符串相同的子串的个数 对于这种前缀的问题,通常通过扩展kmp来解决 其实吧这是我第一次做扩展kmp的题目,原来确实看过这个概念,今天突然做到,所以这个扩展kmp的模 ...

  7. DotNetBar v12.3.0.3 Fully Cracked

    PS: 博客园的程序出现问题,导致我的博客不能访问(转到登录页),而我自己由于 Cookies 问题,一直可以访问,所以一直未发现该问题. 感谢冰河之刃告知,thx! 更新信息: http://www ...

  8. sql学习资料

    http://blog.sina.com.cn/s/articlelist_1594135432_9_1.html

  9. Mvc5 Html.EditorFor

    如果对缺省的样子不满意, 可以有模板,寻寻觅觅,摸索出 在Views\Shared\EditorTemplates下创建String.cshtml 必须的是EditorTemplates文件夹 @{ ...

  10. python视频教程:十分钟快速入门python

    想要学习python这门语言,却始终找不到一个全面的Python视频教程,倘若你是真心想学好一门语言,小编建议你亲自动手实践的.下面来看看入门python的学习教程. Python的语言特性 Pyth ...