7 2 3 4 100 5
import java.util.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ int n = in.nextInt(); int[] arr = new int[n]; for(int i = 0; i<n; i++) arr[i] = in.nextInt(); int length = solution(arr); System.out.println("length: "+length); } } public static int solution(int[] arr){ int len = arr.length; int left = 0, right = 0, res = 0, valid = 0; while(right < len){ if(right > 0 && arr[right] < arr[right-1]) valid++; while(valid > 1){ left++; if(arr[left] < arr[left-1]) valid--; } res = Math.max(res, right-left+1); right++; } return res; } }
全部评论
(2) 回帖