LeetCode 575 Distribute Candies 解题报告
题目要求
Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute these candies equally in number to brother and sister. Return the maximum number of kinds of candies the sister could gain.
题目分析及思路
给定一个长度为偶数的整数数组,其中不同数字代表不同种类的糖果,且一个数字代表一颗该种糖果。需要将这些糖果平均分给男生和女生,要求返回女生能得到糖果种类的最大值。可以先利用集合特性获得糖果种类数及女生数量,若种类数少于女生数量,则返回种类数;否则返回女生数量。
python代码
class Solution:
def distributeCandies(self, candies: List[int]) -> int:
candy_kinds = len(set(candies))
bro_or_sis_num = len(candies)//2
if candy_kinds < bro_or_sis_num:
return candy_kinds
else:
return bro_or_sis_num
LeetCode 575 Distribute Candies 解题报告的更多相关文章
- 【LeetCode】575. Distribute Candies 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...
- LeetCode 575. Distribute Candies (发糖果)
Given an integer array with even length, where different numbers in this array represent different k ...
- LeetCode: 575 Distribute Candies(easy)
题目: Given an integer array with even length, where different numbers in this array represent differe ...
- LeetCode 1 Two Sum 解题报告
LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...
- 【LeetCode】Permutations II 解题报告
[题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...
- 【LeetCode】Island Perimeter 解题报告
[LeetCode]Island Perimeter 解题报告 [LeetCode] https://leetcode.com/problems/island-perimeter/ Total Acc ...
- 【LeetCode】01 Matrix 解题报告
[LeetCode]01 Matrix 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/01-matrix/#/descripti ...
- 【LeetCode】Largest Number 解题报告
[LeetCode]Largest Number 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/largest-number/# ...
- 【LeetCode】Gas Station 解题报告
[LeetCode]Gas Station 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/gas-station/#/descr ...
随机推荐
- LeetCode: Next Permutation 解题报告
Next Permutation Implement next permutation, which rearranges numbers into the lexicographically nex ...
- 解决 meld 出现 locale.setlocale(locale.LC_ALL,'') 失败的问题
. . . . . meld 是一款免费的文件比较工具,官网地址:http://meldmerge.org/ 在 Linux 环境使用 meld 的时候,可能会由于语言区域的配置问题导致它无法启动,会 ...
- const读书笔记
Const 的使用读书笔记 Const的主要主要用法有: 常变量: const 类型说明符 变量名 常引用: const 类型说明符 &引用名 常对象: 类名 const 对象名 常成员函数 ...
- android:onClick都做了什么
同步发表于 http://avenwu.net/viewinject/2015/01/28/android_onclick/ 相信大家都知道在layout里面可以给view写android:onCli ...
- OpenGL 获取当前屏幕坐标的三维坐标(gluUnProject使用例子 VS+glut)
本例子参考于网络,并进行了一些修改,使用glut+vs2008来实现. 在鼠标点击处重新画一个旋转的红色立方体! 参考代码如下: C++ Code 123456789101112131415161 ...
- 根据key删除Map集合中的key-value映射
一:在遍历Map时是不可以删除key-value映射的,如果根据key删除,如下: public static void main(String[] args) { Map<String,Obj ...
- [IR] Suffix Trees and Suffix Arrays
前缀树 匹配前缀字符串是不言自明的道理. 1. 字符串的快速检索 2. 最长公共前缀(LCP) 等等 树的压缩 后缀树 Let s=abab, a suffix tree of s is a comp ...
- [Artoolkit] Marker of nftSimple
重点看:markers.dat 的解析原理 1. int main(int argc, char** argv) { ]; const char *cparam_name = "Data2/ ...
- fs项目---->async/await的学习(一)
2018-07-11号,我来到了fs项目组担任后端开发的角色.这是我来thoughtworks以来首个的正式项目,不管是在技术还是在敏捷的实践中都是受益匪浅.来感受tw特殊的文化的同时,我希望自己能够 ...
- HRMS文件解析2
returntablefieldColorFilterGray()函数在/lib/select_menu.php文件中,函数如下: function returntablefieldColorFilt ...