import java.util.*; public class Demo21 { /** 请完成下面这个函数,实现题目要求的功能 **/ /** * 当然,你也可以不按照这个模板来作答,完全按照自己的想法来 ^-^ **/ static int pick(int[] peaches) { int result = 0; if(peaches == null || peaches.length == 0){ return result; } int len = peaches.length; List<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>(); for(int i = 0; i < len; i++) list.add(new ArrayList<Integer>()); for(int i = 0; i < len; i++){ ArrayList<Integer> blist = list.get(i); int max = peaches[i]; blist.add(max); for(int j = i + 1; j < len; j++){ if(peaches[j] >= max){ //记录串中最大的数 max = peaches[j]; blist.add(max); } } } for(int i = 0; i < len; i++){ if(list.get(i).size() > result) result = list.get(i).size(); } return result; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int trees = Integer.parseInt(in.nextLine().trim()); int[] peaches = new int[trees]; for (int i = 0; i < peaches.length; i++) { peaches[i] = Integer.parseInt(in.nextLine().trim()); } System.out.println(pick(peaches)); } }
点赞 评论

相关推荐

2024-12-21 10:42
已编辑
江西软件职业技术大学 Java
新宿站不停:该提升学历就提升学历,菜了就多练。没事找牛马公司虐自己是吧? 谁没事说自己“经验少”,这不自己把自己塞剎鼻hr嘴里找🐴吗
点赞 评论 收藏
分享
牛客网
牛客企业服务