首页 > TAG信息列表 > deliciousness

【leetcode】1711. 大餐计数(count-good-meals)(二分)[中等]

链接 https://leetcode-cn.com/problems/count-good-meals/ 耗时 解题:5 h 16 min 题解:38 min 题意 大餐 是指 恰好包含两道不同餐品 的一餐,其美味程度之和等于 2 的幂。 你可以搭配 任意 两道餐品做一顿大餐。 给你一个整数数组 deliciousness ,其中 deliciousness[i] 是第 i

文巾解题 1711. 大餐计数

1 题目描述 2 解题思路 先设立一个哈希表,来得到不同的美味值分别有几道菜。然后对幂值和美味值进行遍历。 import math class Solution(object): def countPairs(self, deliciousness): """ :type deliciousness: List[int] :rtype: int "

Leetcode 1711 大餐计数

题目   思路  本题的思路是从提示的数据范围往回推的,由数据范围可知一顿大餐的美味程度最大为2的21次方(2*2的20次方),也就是说能够选出的所有大餐的组合的可能值只能在0,2^1,2^2...2^21次方之间,所以可以用枚举可能的大餐美味值的方法来确定答案。具体做法是先遍历数组,统计每个

1711. Count Good Meals

package LeetCode_1711 /** * 1711. Count Good Meals * https://leetcode.com/problems/count-good-meals/ * A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two. You can pick any two diffe