-
Notifications
You must be signed in to change notification settings - Fork 34
/
Solution.java
29 lines (29 loc) · 943 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class Solution {
public boolean increasingTriplet(int[] nums) {
if (nums.length<3) {
return false;
}
List<Integer> list=new ArrayList<Integer>();
list.add(nums[0]);
for (int i = 1; i < nums.length; i++) {
if (list.size()==1) {
if (nums[i]<=list.get(0)) {
list.remove(0);
}
list.add(nums[i]);
}else {
if (nums[i]!=list.get(0)&&nums[i]!=list.get(1)) {
if (nums[i]>list.get(0)&&nums[i]>list.get(1)) {
return true;
}else if (nums[i]>list.get(0)&&nums[i]<list.get(1)) {
list.remove(1);
}else {
list.remove(0);
}
list.add(nums[i]);
}
}
}
return false;
}
}