File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
2018-feb/adhoc-thinking/src/com/alg/top20/adhoc Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .alg .top20 .adhoc ;
2+
3+ public class IncreasingTriplet {
4+
5+ public static boolean hasIncrTriplet1 (int [] in ) {
6+ for (int i = 0 ; i < in .length ; ++i ) {
7+ for (int j = i +1 ; j < in .length ;++j ) {
8+ if (in [j ] < in [i ]) continue ;
9+ for (int k = j +1 ; k < in .length ;++k ) {
10+ if (in [k ] > in [j ]) return true ;
11+ }
12+ }
13+ }
14+ return false ;
15+ }
16+
17+ public static boolean hasIncrTriplet2 (int [] in ) {
18+ int min1 = Integer .MAX_VALUE ;
19+ int min2 = Integer .MAX_VALUE ;
20+ for (int i = 0 ; i < in .length ; ++i ) {
21+ if (in [i ] < min1 ) min1 = in [i ];
22+
23+ else if (in [i ] < min2 ) min2 = in [i ];
24+ else return true ;
25+ }
26+ return false ;
27+ }
28+ public static void main (String [] args ) {
29+ // TODO Auto-generated method stub
30+
31+ }
32+
33+ }
You can’t perform that action at this time.
0 commit comments