class Solution {
public boolean lemonadeChange(int[] bills) {
int num5 = 0;
int num10 = 0;
for(int i = 0;i<bills.length;i++){
if(bills[i] == 5){
num5++;
}else if(bills[i] == 10){
if(num5<=0)
return false;
num5--;
num10++;
}else if(bills[i] == 20){
if(num10>0){
num10--;
if(num5>0){
num5--;
}else{
return false;
}
}else{
if(num5>=3){
num5-=3;
}else{
return false;
}
}
}
}
return true;
}
}
class Solution {
public static int[][] reconstructQueue(int[][] people) {
int[][] res = new int[people.length][2];
PriorityQueue<Integer> queue = new PriorityQueue<>((o1, o2) -> {
if (people[o1][0] == people[o2][0]) {
return Integer.compare(people[o1][1], people[o2][1]);
} else {
return Integer.compare(people[o2][0], people[o1][0]);
}
});
for (int i = 0; i < people.length; i++) {
queue.add(i);
}
int index = 0;
while (!queue.isEmpty()) {
Integer poll = queue.poll();
res[index][0] = people[poll][0];
res[index][1] = people[poll][1];
index++;
}
List<int[]> list = new LinkedList<>();
for (int i = 0; i < res.length; i++) {
int[] temp = {res[i][0], res[i][1]};
list.add(res[i][1], temp);
}
return list.toArray(new int[people.length][]);
}
}
class Solution {
public static int findMinArrowShots(int[][] points) {
Arrays.sort(points, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if (o1[0] == o2[0]) {
return Integer.compare(o1[1], o2[1]);
}
return Integer.compare(o1[0], o2[0]);
}
});
int res = 1;
int start = points[0][0];
int end = points[0][1];
for (int i = 1; i < points.length; i++) {
if (points[i][0] > end || start > points[i][1]) {
res++;
start = points[i][0];
end = points[i][1];
} else {
start = points[i][0];
if (end > points[i][1])
end = points[i][1];
}
}
return res;
}
}