classSolution{publicbooleanlemonadeChange(int[] bills){int five =0;int ten =0;for(int i =0; i < bills.length; i++){if(bills[i]==5)
five++;elseif(bills[i]==10){
five--;
ten++;}else{if(ten >0){
ten--;
five--;}else{
five -=3;}}if(five <0|| ten <0)returnfalse;}returntrue;}}
406.根据身高重建队列
classSolution{publicint[][]reconstructQueue(int[][] people){Arrays.sort(people,(a, b)->{if(a[0]== b[0])return a[1]- b[1];return b[0]- a[0];});List<int[]> list =newLinkedList<>();// 按身高排序后,每次插入的人身高都比队中的低,不会影响队中人的k值// 队中人身高都比插入的人高,所以插入直接按k值位置插入for(int[] p : people){
list.add(p[1], p);}return list.toArray(newint[people.length][]);}}
452.用最少数量的箭引爆气球
classSolution{publicintfindMinArrowShots(int[][] points){Arrays.sort(points,(a, b)->Integer.compare(a[0], b[0]));int count =1;for(int i =1; i < points.length; i++){if(points[i][0]> points[i -1][1])
count++;else
points[i][1]=Math.min(points[i -1][1], points[i][1]);}return count;}}