【leetcode】1276. Number of Burgers with No Waste of Ingredients
题目如下:
Given two integers
tomatoSlicesandcheeseSlices. The ingredients of different burgers are as follows:
- Jumbo Burger: 4 tomato slices and 1 cheese slice.
- Small Burger: 2 Tomato slices and 1 cheese slice.
Return
[total_jumbo, total_small]so that the number of remainingtomatoSlicesequal to 0 and the number of remainingcheeseSlicesequal to 0. If it is not possible to make the remainingtomatoSlicesandcheeseSlicesequal to 0 return[].Example 1:
Input: tomatoSlices = 16, cheeseSlices = 7
Output: [1,6]
Explantion: To make one jumbo burger and 6 small burgers we need 4*1 + 2*6 = 16 tomato and 1 + 6 = 7 cheese. There will be no remaining ingredients.Example 2:
Input: tomatoSlices = 17, cheeseSlices = 4
Output: []
Explantion: There will be no way to use all ingredients to make small and jumbo burgers.Example 3:
Input: tomatoSlices = 4, cheeseSlices = 17
Output: []
Explantion: Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining.Example 4:
Input: tomatoSlices = 0, cheeseSlices = 0
Output: [0,0]Example 5:
Input: tomatoSlices = 2, cheeseSlices = 1
Output: [0,1]Constraints:
0 <= tomatoSlices <= 10^70 <= cheeseSlices <= 10^7
解题思路:解二元一次方程。
代码如下:
class Solution(object):
def numOfBurgers(self, tomatoSlices, cheeseSlices):
"""
:type tomatoSlices: int
:type cheeseSlices: int
:rtype: List[int]
"""
if (tomatoSlices - 2*cheeseSlices)%2 != 0 or (4*cheeseSlices - tomatoSlices) % 2 != 0:
return []
elif (tomatoSlices - 2*cheeseSlices)/2 < 0 or (4*cheeseSlices - tomatoSlices) / 2 < 0:
return []
return [(tomatoSlices - 2*cheeseSlices)/2, (4*cheeseSlices - tomatoSlices) / 2]
【leetcode】1276. Number of Burgers with No Waste of Ingredients的更多相关文章
- 【LeetCode】Largest Number 解题报告
[LeetCode]Largest Number 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/largest-number/# ...
- 【LeetCode】792. Number of Matching Subsequences 解题报告(Python)
[LeetCode]792. Number of Matching Subsequences 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
- 【LeetCode】673. Number of Longest Increasing Subsequence 解题报告(Python)
[LeetCode]673. Number of Longest Increasing Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https:/ ...
- 【LeetCode】Single Number I & II & III
Single Number I : Given an array of integers, every element appears twice except for one. Find that ...
- 【LeetCode】476. Number Complement (java实现)
原题链接 https://leetcode.com/problems/number-complement/ 原题 Given a positive integer, output its comple ...
- 【LeetCode】191. Number of 1 Bits 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 右移32次 计算末尾的1的个数 转成二进制统计1的个 ...
- 【LeetCode】1128. Number of Equivalent Domino Pairs 等价多米诺骨牌对的数量(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典统计 代码 复杂度分析 日期 题目地址:http ...
- 【LeetCode】447. Number of Boomerangs 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] 题目地址:https:/ ...
- 【LeetCode】996. Number of Squareful Arrays 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...
随机推荐
- C++中如何调用DLL文件
一.动态链接库简介 动态库链接库英文位DLL,是Dynamic Link Library的缩写形式,DLL不是可执行文件.动态链接提供了一种方法,使进程可以调用不属于其可执行文件代码的函数.函数可执行 ...
- PAT B1042 挖掘机哪家强
AC代码 #include <cstdio> #include <algorithm> using namespace std; const int max_n = 11000 ...
- Codeforces 1236E. Alice and the Unfair Game
传送门 首先可以注意到对于固定的起点 $S$ ,它最终能走到的终点一定是一段区间 这个用反证法容易证明,假设合法区间存在断点,这个点左右都可以作为终点 那么分成区间断点在起点左边和起点右边讨论一下即可 ...
- nignx简单介绍
Nginx的产生 没有听过Nginx?那么一定听过它的"同行"Apache吧!Nginx同Apache一样都是一种WEB服务器.基于REST架构风格,以统一资源描述符(Unifor ...
- 点击导航目录页面滑动到指定div区域
$(document).on("click", ".navbar-nav li[link]", function() { nav.find('li').remo ...
- inline元素、block元素
inline元素 不会独占一行,相邻的行内元素会排列在同一行内,直到一行排不下才会换行 高.行高.以及外边距和内边距不可改变 宽度就是它的文字或图片的宽度,不可改变,随元素内容变化而变化 内联元素只能 ...
- JavaScript函数式编程——柯里化
柯里化原理 如何实现柯里化 柯里化的应用 一.柯里化原理 柯里化:在数学和计算机科学中,柯里化是一种使用多个参数的一个函数转换成一系列使用一个参数的函数的技术. 前端使用柯里化的用途主要就应该是简化代 ...
- HTML之美化盒子
1. 美化盒子 1.1. 美化文本 1.1.1. 字体大小[font-size]: 字符框的高度,可继承,默认值medium,16px.基准字号:浏览器设置的默认字体大小,通 ...
- Odoo的菜单项
用户界面的入口是菜单项,菜单项形成一个层级结构,最顶级项为应用,其下一级为每个应用的主菜单.还可以添加更深的子菜单.可操作菜单与窗口操作关联,它告诉客户端在点击了菜单项后应执行什么操作. 菜单项存储在 ...
- 09-【el表达式和jstl标签库】
el表达式和jstl标签库 一:el表达式:表达式语言,jsp页面获取数据比较简单1.el表达式的语法(掌握)el表达式通常取值是获取作用域对象中的属性值:${属性名}=>是el表达式的简写的形 ...