1
1
class Solution {
2
- public boolean hasIncreasingSubarrays (List <Integer > nums , int k ) {
3
-
4
- int n = nums .size ();
5
- if (n <2 *k ) return false ;
6
- if (k ==1 ) return true ;
7
- for (int i =0 ;i <n -2 *k +1 ;i ++){
8
- if (check (i ,k ,nums )==true ){
9
- return true ;
10
- }
11
- }
12
- return false ;
13
- }
14
- public boolean check (int i , int k , List <Integer > nums ){
15
- int n = nums .size ();
16
- for (int j =i ;j <i +2 *k -1 && j <n -1 ;j ++){
17
- int curr = nums .get (j ) , next = nums .get (j +1 );
18
- if (curr >=next && j !=i +k -1 ){
19
- return false ;
20
- }
21
- if (j == i +k -1 ){
22
- continue ;
23
- }
2
+ // public boolean hasIncreasingSubarrays(List<Integer> nums, int k) {
3
+ // int n = nums.size();
4
+ // if(n<2*k) return false;
5
+ // if(k==1) return true;
6
+ // for(int i=0;i<n-2*k+1;i++){
7
+ // if(check(i,k,nums)==true){
8
+ // return true;
9
+ // }
10
+ // }
11
+ // return false;
12
+ // }
13
+ // public boolean check(int i , int k , List<Integer> nums){
14
+ // int n = nums.size();
15
+ // for(int j=i;j<i+2*k-1 && j<n-1 ;j++){
16
+ // int curr = nums.get(j) , next = nums.get(j+1);
17
+ // if(curr >=next && j!=i+k-1){
18
+ // return false;
19
+ // }
20
+ // if(j == i+k-1){
21
+ // continue;
22
+ // }
23
+ // }
24
+ // return true;
25
+ // }
26
+ // public boolean hasIncreasingSubarrays(int[] nums, int k) {
27
+ // int n = nums.length;
28
+ // if (n / k < 2) return false;
29
+ // if (k == 1) return true;
30
+
31
+ // int[] vis = new int[n];
32
+ // int start = 0, end = 1;
33
+
34
+ // while (end < n) {
35
+ // while (end < n && nums[end] > nums[end - 1]) {
36
+ // if (end - start + 1 == k) {
37
+ // vis[start] = 1;
38
+ // start++;
39
+ // }
40
+ // end++;
41
+ // }
42
+ // start = end;
43
+ // end++;
44
+ // }
45
+
46
+ // for (int i = 0; i <= n - (2 * k); i++) {
47
+ // if (vis[i] == 1 && vis[i + k] == 1) return true;
48
+ // }
49
+ // return false;
50
+ // }
51
+ public boolean hasIncreasingSubarrays (List <Integer > nums ,int k ) {
52
+ int res = 0 ; int prev = 0 ; int curr = 1 ;
53
+ for (int i = 1 ; i <nums .size (); i ++){
54
+ if (nums .get (i ) > nums .get (i -1 )){
55
+ curr ++;
56
+ }else {
57
+ prev = curr ;
58
+ curr = 1 ;
24
59
}
25
- return true ;
60
+ res = Math .max (res , Math .max (curr /2 , Math .min (prev , curr )));
61
+ }
62
+ return res >=k ;
26
63
}
27
64
}
0 commit comments