860. 柠檬水找零
public class Solution {
public bool LemonadeChange(int[] bills) {
Dictionary<int, int> dict = new Dictionary<int, int>() {
{5,0},
{10,0}
};
int count = 0;
for(int i = 0;i < bills.Length;i++)
{
if(bills[i] == 5) dict[5]++;
if(bills[i] == 10)
{
dict[10]++;
if(dict[5] > 0) dict[5]--;
else return false;
}
if(bills[i] == 20)
{
if(dict[10]> 0 && dict[5] > 0)
{
dict[10]--;
dict[5]--;
} else if(dict[5] >= 3)
{
dict[5]-=3;
}
else return false;
}
}
return true;
}
}
452. 用最少数量的箭引爆气球
public class Solution {
public static int CompareStrings(int[] a, int[] b)
{
return a[0] < b[0] ? -1 : 1;
}
public int FindMinArrowShots(int[][] points) {
int sum = 1;
Array.Sort(points, CompareStrings);
for (int i = 1; i < points.Length; i++)
{
if (points[i][0] > points[i - 1][1]) sum++;
else {
points[i][1] = points[i - 1][1] < points[i][1] ? points[i - 1][1] : points[i][1]; // 更新重叠气球最小右边界
}
}
return sum;
}
}