【LeetCode】每日一题 2023_12_25 不浪费原料的汉堡制作方案(数学,解二元一次方程)

文章目录

  • 刷题前唠嗑
  • 题目:不浪费原料的汉堡制作方案
    • 题目描述
    • 代码与解题思路
  • 结语

刷题前唠嗑

【LeetCode】每日一题 2023_12_25 不浪费原料的汉堡制作方案(数学,解二元一次方程)_第1张图片
LeetCode?启动!!!

题目:不浪费原料的汉堡制作方案

题目链接:1276. 不浪费原料的汉堡制作方案

题目描述

【LeetCode】每日一题 2023_12_25 不浪费原料的汉堡制作方案(数学,解二元一次方程)_第2张图片

代码与解题思路

func numOfBurgers(tomatoSlices int, cheeseSlices int) []int {
    if tomatoSlices%2 != 0 || tomatoSlices < cheeseSlices*2 || cheeseSlices*4 < tomatoSlices {
        return nil
    }
    return []int{tomatoSlices/2-cheeseSlices, cheeseSlices*2-tomatoSlices/2}
}

你敢信吗,这道题居然是解二元一次方程,谢谢,我都傻眼了

设巨无霸 x 个,小皇堡 y 个

4x + 2y = tomatoSlices
x + y = cheeseSlices

结语

怎么 LeetCode 最近老出数学题?

你可能感兴趣的:(LeetCode,每日一题,leetcode,算法,职场和发展)