Skip to content

1276. Number of Burgers with No Waste of Ingredients

  • Time:
  • Space:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class Solution {
 public:
  vector<int> numOfBurgers(int tomatoSlices, int cheeseSlices) {
    if (tomatoSlices % 2 == 1 || tomatoSlices < 2 * cheeseSlices ||
        tomatoSlices > cheeseSlices * 4)
      return {};

    int jumboBurgers = (tomatoSlices - 2 * cheeseSlices) / 2;

    return {jumboBurgers, cheeseSlices - jumboBurgers};
  }
};
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class Solution {
  public List<Integer> numOfBurgers(int tomatoSlices, int cheeseSlices) {
    if (tomatoSlices % 2 == 1 || tomatoSlices < 2 * cheeseSlices || tomatoSlices > cheeseSlices * 4)
      return new ArrayList<>();

    int jumboBurgers = (tomatoSlices - 2 * cheeseSlices) / 2;

    return new ArrayList<>(Arrays.asList(jumboBurgers, cheeseSlices - jumboBurgers));
  }
}
1
2
3
4
5
6
7
8
class Solution:
  def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:
    if tomatoSlices % 2 == 1 or tomatoSlices < 2 * cheeseSlices or tomatoSlices > cheeseSlices * 4:
      return []

    jumboBurgers = (tomatoSlices - 2 * cheeseSlices) // 2

    return [jumboBurgers, cheeseSlices - jumboBurgers]