LC.P1276[不浪费原料的汉堡制作方案] 方法一:数学求解二元一次方程即可 1234567891011class Solution { public List<Integer> numOfBurgers(int tomatoSlices, int cheeseSlices) { if (tomatoSlices % 2 != 0 || tomatoSlices < cheeseSlices * 2 || cheeseSlices * 4 < tomatoSlices) { return new ArrayList<>(); } List<Integer> ans = new ArrayList<>(); ans.add(tomatoSlices / 2 - cheeseSlices); ans.add(cheeseSlices * 2 - tomatoSlices / 2); return ans; }} 时间复杂度:$O(1)$ 空间复杂度:$O(1)$