leetcode334
public class Solution
{
public bool IncreasingTriplet(int[] nums)
{
var len = nums.Length;
if (len < )
{
return false;
} for (int i = ; i <= len - ; i++)
{
for (int j = i + ; j <= len - ; j++)
{
if (nums[i] < nums[j])
{
for (int k = j + ; k <= len - ; k++)
{
if (nums[j] < nums[k])
{
return true;
}
}
} }
} return false;
}
}
补充一个python实现:
import sys
class Solution:
def increasingTriplet(self, nums: 'List[int]') -> bool:
smaller = sys.maxsize
small = sys.maxsize
for num in nums:
if num <= smaller:
smaller = num
elif num <= small:
small = num
else:
return True
return False
leetcode334的更多相关文章
- LeetCode-334. Increasing Triplet Subsequence
Description: Given an unsorted array return whether an increasing subsequence of length 3 exists or ...
- [Swift]LeetCode334. 递增的三元子序列 | Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- leetcode334 递增的三元子序列
class Solution { public: bool increasingTriplet(vector<int>& nums) { //使用双指针: int len=nums ...
- leetcode探索中级算法
leetcode探索中级答案汇总: https://leetcode-cn.com/explore/interview/card/top-interview-questions-medium/ 1)数 ...
随机推荐
- MySQL 5.7笔记
1. 初始化 重命名my-default.ini为my.ini 添加character_set_server=utf8 运行mysqld --initialize 2. 重置密码 服务器运行: mys ...
- Redis安全性配置
最近Redis刚爆出一个安全性漏洞,我的服务器就“光荣的”中招了.黑客攻击的基本方法是: 扫描Redis端口,直接登录没有访问控制的Redis 修改Redis存盘配置:config set dir / ...
- #Eclipse web工程 部署 三种方式 3
Eclipse web工程 部署 三种方式 3.热部署 在Eclipse中,实现 修改一个.java文件或者.jsp文件甚至是配置文件,不需要重启WEB服务器的前提下让修改生效,实现tomcat自动加 ...
- <context:annotation-config/>,<context:component-scan/>,<mvc:annotation-driven/>区分
链接:http://blog.csdn.net/baple/article/details/16864175 链接:http://blog.csdn.net/Baple/article/details ...
- JQ 知识点集合
数组与字符串间的转换 一.数组转字符串(将数组元素用某个字符连接成字符串) var a, b; a = new Array(0,1,2,3,4); b = a.join("-"); ...
- BZOJ5369 [Pkusc2018]最大前缀和
题意 小C是一个算法竞赛爱好者,有一天小C遇到了一个非常难的问题:求一个序列的最大子段和. 但是小C并不会做这个题,于是小C决定把序列随机打乱,然后取序列的最大前缀和作为答案. 小C是一个非常有自知之 ...
- BZOJ1495 [NOI2006]网络收费
题意 传送门 MY市NS中学,大概是绵阳市南山中学. 分析 参照Maxwei_wzj的题解. 因为成对的贡献比较难做,我们尝试把贡献算到每一个叶子节点上.我们发现按照题目中的收费方式,它等价于对于每棵 ...
- selectToUISlider
版权声明:本文为LZUGIS原创文章,未经同意不得转载. https://blog.csdn.net/GISShiXiSheng/article/details/24304321 用过google e ...
- 【转】一步一步教你在Ubuntu12.04搭建gstreamer开发环境
原文网址:http://blog.csdn.net/xsl1990/article/details/8333062 闲得蛋疼 无聊寂寞冷 随便写写弄弄 看到网上蛮多搭建gstreamer开 ...
- servlet运作机制
最近研究zipkin,在研究客户端brave的时候,才算开始理解servlet了. servlet只是tomcat被实例化一次: 之后每次访问其实都是对同一个servlet示例操作:所以, ...