之前的题使用同样的代码,在eclipse上跑没问题,在牛客网上就没有输出,而且是对有的用例有输出,有的没有。
import java.util.Scanner; import java.util.ArrayList; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] zhuang = new int[n]; for(int i=0;i<n;i++){ zhuang[i] = scan.nextInt(); } ArrayList<Integer> list = new ArrayList<Integer>(); System.out.println(GetResult(n,zhuang,list)); } public static int GetResult(int n,int[] zhuang,ArrayList<Integer> result){ if(n<=0){ result.add(0); return 0; } else{ int step_max =1; int step[] = new int[n]; for(int i=0;i<n;i++){ step[i] = 1; for(int j=i-1;j>=0;j--){ if(zhuang[j]< zhuang[i]){ if(step[j]>=step[i]){ step[i] = step[j]+1; if(step_max < step[i]){ step_max = step[i]; } } } } } result.add(step_max); return step_max; } } }
全部评论
(0) 回帖