Skip to content

Commit 132d5f1

Browse files
committed
Create 1276. 不浪费原料的汉堡制作方案.js
1 parent fd08a52 commit 132d5f1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number} tomatoSlices
3+
* @param {number} cheeseSlices
4+
* @return {number[]}
5+
*/
6+
var numOfBurgers = function (tomatoSlices, cheeseSlices) {
7+
if (tomatoSlices % 2 !== 0) {
8+
return [];
9+
}
10+
const maxJumbo = Math.floor(tomatoSlices / 4);
11+
const maxSmall = Math.floor(tomatoSlices / 2);
12+
if (cheeseSlices > maxSmall || cheeseSlices < maxJumbo) {
13+
return [];
14+
}
15+
return [maxSmall - cheeseSlices, Math.floor((tomatoSlices - (maxSmall - cheeseSlices) * 4) / 2)];
16+
};

0 commit comments

Comments
 (0)