一、题目
1、题目描述
圣诞活动预热开始啦,汉堡店推出了全新的汉堡套餐。为了避免浪费原料,请你帮他们制定合适的制作计划。
给你两个整数
tomatoSlices
和cheeseSlices
,分别表示番茄片和奶酪片的数目。不同汉堡的原料搭配如下:
- 巨无霸汉堡:4 片番茄和 1 片奶酪
- 小皇堡:2 片番茄和 1 片奶酪
请你以
[total_jumbo, total_small]
([巨无霸汉堡总数,小皇堡总数])的格式返回恰当的制作方案,使得剩下的番茄片tomatoSlices
和奶酪片cheeseSlices
的数量都是0
。如果无法使剩下的番茄片
tomatoSlices
和奶酪片cheeseSlices
的数量为0
,就请返回[]
。
2、接口描述
class Solution {
public:
vector<int> numOfBurgers(int tomatoSlices, int cheeseSlices) {
}
};
3、原题链接
二、解题报告
1、思路分析
解二元一次方程组即可,注意判断无解情况即可
2、复杂度
时间复杂度:O(1) 空间复杂度:O(1)
3、代码详解
class Solution {
public:
int x , y;
vector<int> numOfBurgers(int m, int n) {
x = (m - 2 * n) / 2;
y = n - x;
if((m - 2 * n) & 1 || x < 0 || y < 0) return {};
return {x , y};
}
};