public int[] solve (int[] a) { List<Integer> list = new ArrayList<>(); for(int i=0;i<a.length;i++){ list.add(a[i]); } List<Integer> list1 = new ArrayList<>(); Arrays.sort(a); boolean[] paduan = new boolean[a.length]; int j = a.length-1; Stack<Integer> stack = new Stack<>(); for(int i=0;i<a.length;i++){ int temp = list.get(i); if(temp!=a[j]){ stack.push(temp); paduan[i]=true; } if(temp==a[j]){ if(paduan[i]==true){ list1.add(stack.pop()); }else{ paduan[i]=true; list1.add(temp); } j--; } } while(!stack.isEmpty()){ list1.add(stack.pop()); } for(int i=0;i<list1.size();i++){ a[i] = list1.get(i); } return a; }
点赞 4

相关推荐

Java大菜狗:纯纯招黑奴,一天还不到两百那么多要求,还不迟到早退,以为啥啊,给一点工资做一堆活,还以不拖欠员工工资为荣,这是什么值得骄傲的事情吗,纯纯***公司
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务