Number of Burgers with No Waste of Ingredients LeetCode solution in JavaScript

1
/**
2
* @param {number} tomatoSlices
3
* @param {number} cheeseSlices
4
* @return {number[]}
5
*/
6
var numOfBurgers = function (tomatoSlices, cheeseSlices) {
7
if (tomatoSlices & 1) return []; // return [] if tomatoSlices is odd
8
const j = (tomatoSlices >> 1) - cheeseSlices; // jumbo = (tomatoSlices / 2) - cheeseSlices
9
return j < 0 || j > cheeseSlices ? [] : [j, cheeseSlices - j]; // small = cheeseSlices - jumbo, if any of jmbo and small < 0 return [] otherwise return [jumbo, small]
10
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0