LEETCODE1276. 不浪费原料的汉堡制作方案(java)

class Solution {
    public List numOfBurgers(int tomatoSlices, int cheeseSlices) {
        List list = new ArrayList<>();

        if(tomatoSlices % 2 != 0 || cheeseSlices * 2 > tomatoSlices){
            return new ArrayList<>();
        }
        //解方程一元二次方程
        int big  = (tomatoSlices - 2 * cheeseSlices) / 2;
        int small = (4 * cheeseSlices - tomatoSlices) / 2;
        if(big > cheeseSlices){
            return new ArrayList<>();
        }
        list.add(big);
        list.add(small);
        return list;
    }
}

你可能感兴趣的:(leetcode,java,开发语言,算法,leetcode)