Increasing Triplet Subsequence
2016-06-14 05:17
489 查看
这也是一道智力题,没那么复杂,也没那么直白。
public class Solution {
public boolean increasingTriplet(int[] nums) {
if (nums == null || nums.length < 3) {
return false;
}
int firstMin = Integer.MAX_VALUE, secondMin = Integer.MAX_VALUE;
for (int i: nums) {
if (i <= firstMin) {
firstMin = i;
} else if (i <= secondMin) {
secondMin = i;
} else {
return true;
}
}
return false;
// int n1 = Integer.MIN_VALUE, n2 = Integer.MIN_VALUE, n3 = Integer.MIN_VALUE;
// for (int i: nums) {
// if (i > n1) {
// n3 = n2;
// n2 = n1;
// n1 = i;
// } else if (i > n2) {
// n3 = n2;
// n2 = i;
// } else if (i > n3) {
// n3 = i;
// }
// }
// //if (n1 > n2 && n2 > n3) {
// if (n1 > n2 && n2 > n3 && n3 != Integer.MIN_VALUE) {
// return true;
// } else {
// return false;
// }
}
}
public class Solution {
public boolean increasingTriplet(int[] nums) {
if (nums == null || nums.length < 3) {
return false;
}
int firstMin = Integer.MAX_VALUE, secondMin = Integer.MAX_VALUE;
for (int i: nums) {
if (i <= firstMin) {
firstMin = i;
} else if (i <= secondMin) {
secondMin = i;
} else {
return true;
}
}
return false;
// int n1 = Integer.MIN_VALUE, n2 = Integer.MIN_VALUE, n3 = Integer.MIN_VALUE;
// for (int i: nums) {
// if (i > n1) {
// n3 = n2;
// n2 = n1;
// n1 = i;
// } else if (i > n2) {
// n3 = n2;
// n2 = i;
// } else if (i > n3) {
// n3 = i;
// }
// }
// //if (n1 > n2 && n2 > n3) {
// if (n1 > n2 && n2 > n3 && n3 != Integer.MIN_VALUE) {
// return true;
// } else {
// return false;
// }
}
}
相关文章推荐
- leecode_307 Range Sum Query - Mutable
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
- Implement Queue using Stacks
- easyui的tab加载页面中的form重复提交
- IOS创建UI的方式
- CocoaPods问题: CocoaPods was not able to update the `master` repo.if it is a unexpected issue and
- [java线程]---BlockingQueue队列使用
- 揭密小米VR:VR界的MIUI什么样?
- iOS瀑布流简明教程之UICollectionView
- easyui 扩展loading
- easyui获取datagrid某一行记录
- UILabel,自定义cell的自适应高度
- Android学习-手把手教学实现仿微信发带图片朋友圈的UI设计
- HOTPOWER-中国十佳优秀UI设计团队,提供游戏UI顶级服务。
- iOS 中只 导两边圆角的UIButton
- Timer源码之TaskQueue
- Timer源码之TimerThread
- leetcode之Range Sum Query 2D - Immutable
- requireJS 简要介绍和完整例子
- OSG+Duilib显示osg