【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 ...
随机推荐
- Analyzing Polyline -- Codeforces Round #123 (Div. 2)
题意:https://codeforc.es/problemset/problem/195/D 求折线段数. 思路: 对pos进行sort,对不同区间段加k,两个dp处理不同k>0 or k&l ...
- GridFS文件操作
目录 1. GridFS介绍 2. GridFS 存取文件测试 2.1 新建项目配置pom.xml 2.2 在application.yml配置mongodb 2.3 GridFS存取文件测试 2.4 ...
- MGR复制
CentOS7 配置如下 5.7.22 Group ReplicationMySQL5.7.22安装略 在三台db服务器上面设置/etc/hosts映射,如下:192.168.1.101 mydb ...
- DashBoard-身份验证
dashboard1.7.1版本之后,新增了用户登录认证的功能. 默认dashboard会跳转到登录页面: 我们可以看到dashboard提供了Kubeconfig和token两种登录方式,我们可以直 ...
- 后端查询树的通用SQL,具备懒加载功能
select t.org_id as key, --key值 t.org_name as title, --标题 t.has_sub as folder, --是否显示文件夹 t.has_sub as ...
- 解决FileInputStream 读取文件中文乱码问题(转)
当Java中使用 FileInputStream 读取txt等文档时,中文会产生乱码,解决方法如下: try { fis = new FileInputStream(file); InputStrea ...
- CentOS 中利用docker安装MySQL
1.前提条件 centos7 且内核版本高于3.10, 可通过命令: uname -r 查看内核版本 2.利用yum 安装docker 安装一些必要的系统工具: sudo yum install -y ...
- vs 2013 设置website项目端口
vs 2015/2013 设置website项目端口 在web项目创建之后,当我想重新debug时,出现the port xxx is in use 错误. 经过netstat分析,发现占用此项目端口 ...
- C#异步编程学习笔记之-async和await(续)
书接上文,本篇主要记录的内容要点:1.针对async和await在实际应用中的使用方式:2.异步方法返回值(有返回值和无返回值)的两种情况: 示例一(无返回值): using System; usin ...
- MFC下调试 出现 Warning: initial dialog data is out of range.
在mfc Debug模式下出现"Warning: initial dialog data is out of range."提示..原因是出现在 DDV_MinMaxInt 对应的 ...