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. 二模 (9) day2

    第一题: 题目大意:求满足条件P的N位二进制数的个数.P:该二进制数有至少3个0或者3个1挨在一起.. N<=20000 解题过程: 1.一开始直接写了个dfs把表打了出来,不过没发现什么规律, ...

  2. Mongoose全面理解

    一.创建schemas 创建schemas的方式: 1 var userSchema = new mongoose.Schema({ 2 name: String, 3 email: String, ...

  3. struts2的 result 通配符 OGNL

    result: 1). result 是 action 节点的子节点 2). result 代表 action 方法执行后, 可能去的一个目的地 3). 一个 action 节点可以配置多个 resu ...

  4. javascript作用域(Scope),简述上下文(context)和作用域的定义

    网页制作Webjx文章简介:这篇文章将正面解决这个问题:简述上下文(context)和作用域的定义,分析可以让我们掌控上下文的两种方法,最后深入一种高效的方案,它能有效解决我所碰到的90%的问题. 作 ...

  5. 增加JVM虚拟机内存,防止内存溢出

    JAVA_OPTS=-Xms512m -Xmx1024m -XX:PermSize=256M -XX:MaxPermSize=512M -XX:MaxNewSize=256m

  6. 踏着前人的脚印学hadoop——ipc中的Client

    1.Client有五个内部类,分别是Call,ParallelCall,ParallelResult,Connetion,ConnectionId 其实这五个类就是去完成两件事情的,一件事情是连接,另 ...

  7. RPI学习--webcam_用fswebcam抓取图片

    若 ls /dev 下没有video0,可以参考http://www.cnblogs.com/skynext/p/3644873.html,更新firmware 1,安装fswebcam: sudo ...

  8. Android 禁用以及捕捉home键

    最近要做个小项目,其中有需要禁止home键的需求,一开始以为不可以,感觉得root一下才行,后来查了一下,发现还是不少朋友都实现了这个功能,现在也引用一下,供大家参考一下: 1. 在activity中 ...

  9. C# 对MongoDB 进行增删改查的简单操作 (转)

    运用到的MongoDB支持的C#驱动,当前版本为1.6.0 下载地址:https://github.com/mongodb/mongo-csharp-driver/downloads 1,连接数据库 ...

  10. 第八章 标准IO库

    1.IO对象时不可复制或者赋值的:也就是说形参或者返回类型也不能为流类型.如果非要传递或者返回IO对象的的话,则必须传递或者返回指向对象的指针或者引用.如:  ofstream &print( ...