Number of Burgers with No Waste of Ingredients LeetCode solution in Java
1class Solution {2public List<Integer> numOfBurgers(int tomatoSlices, int cheeseSlices) {3List<Integer> list = new ArrayList<>();4int ts = tomatoSlices;5int cs = cheeseSlices;6if (ts < cs * 2 || ts > cs * 4 || ts % 2 != 0 || (ts == 0 && cs > 0) || (cs == 0 && ts > 0)) {7return list;8}9int cnt = 0;10while (ts > 0 && cs > 0 && ts != cs * 2) {11ts -= 4;12cnt++;13cs--;14}15list.add(cnt);16list.add(cs);17return list;18}19}