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)数 ...
随机推荐
- Ubuntu下快速建立跨多个平台的cocos2d-x项目
原文:http://www.bennyxu.com/archives/462 这里之讲一点就是如何快速的建立起cocos2d-x项目,同时linux平台的优越性也充分的暴露无遗. 这里默认您已经成功的 ...
- Servlet实现数字字母验证码图片(二)
Servlet实现数字字母验证码图片(二): 生成验证码图片主要用到了一个BufferedImage类,如下:
- CF1130D Toy Train
D Toy Train 开始时,对于一个点 \(x\) ,若没有糖果需要运走,则不考虑; 否则,若点上有 \(k\) 颗糖果需要运走,火车每次只能搭上 \(1\) 个,显然经过这个点至少 \(k\) ...
- [BZOJ5329][SDOI2018]战略游戏
bzoj luogu Description 省选临近,放飞自我的小Q无心刷题,于是怂恿小C和他一起颓废,玩起了一款战略游戏. 这款战略游戏的地图由n个城市以及m条连接这些城市的双向道路构成,并且从任 ...
- c++ hook 钩子的使用介绍
转自:http://www.cnblogs.com/lidabo/archive/2012/11/29/2795269.html 例子:http://www.codeproject.com/Artic ...
- elixir mix开发入门
备注: 简单使用mix 进行项目的生成,同时添加docker 构建支持 1. 生成项目 mix new mydemoproject 输出信息如下: * creating README.md * cre ...
- SQL的 like 中间字符通配 用法
中间的字符也可以用通配符匹配如果业务需求是找出某表中某字段是“好*****上”的数据,SQL语句应该写成 select * from Table where UserName like '%好%上%' ...
- luvcview,使用mplayer查看摄像头和luvcview保存YUV图像视频的播放(转)
luvcview,使用mplayer查看摄像头和luvcview保存YUV图像视频的播放 在mplayer中查看摄像头,可使用如下命令:mplayer tv:// -tv driver=v4l2:in ...
- (二)Fiddler抓取Firefox、Chrome浏览器上的https协议
Fiddler抓取Firefox.Chrome浏览器上的https协议 安装Fiddler后默认只抓取http协议,如果是https协议的话,浏览器就会提示"您的链接并不安全". ...
- requirejs 到底有什么好处?
无论是在backbone时代,还是angularjs 时代 我都用过requirejs, 后来慢慢全都去掉了, 因为在前端开发requirejs 感觉没有带来任何实质性的好处. 从几个方面说说我的感受 ...