575. Distribute Candies
来源:互联网 发布:dbc2000 传奇数据库表 编辑:程序博客网 时间:2024/06/10 23:34
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.Example 1:Input: candies = [1,1,2,2,3,3]Output: 3Explanation:There are three different kinds of candies (1, 2 and 3), and two candies for each kind.Optimal distribution: The sister has candies [1,2,3] and the brother has candies [1,2,3], too. The sister has three different kinds of candies. Example 2:Input: candies = [1,1,2,3]Output: 2Explanation: For example, the sister has candies [2,3] and the brother has candies [1,1]. The sister has two different kinds of candies, the brother has only one kind of candies.
解:看由题可以看出是求数组中不同字符的个数,可以通过python中集合(set)求解,即集合的长度
def distributeCandies(candies): """ :type candies: List[int] :rtype: int """ size = len(set(candies)) num = len(candies) / 2 if size > num: size = num return size
0 0
- 575. Distribute Candies
- 575. Distribute Candies
- LeetCode | 575. Distribute Candies
- 575. Distribute Candies
- 575. Distribute Candies
- leetcode 575. Distribute Candies
- 575. Distribute Candies
- [LeetCode]575. Distribute Candies
- [leetcode]: 575. Distribute Candies
- 575. Distribute Candies
- 575. Distribute Candies
- [leetcode]575. Distribute Candies
- [easy]575. Distribute Candies
- LeetCode 575. Distribute Candies
- leetcode.575. Distribute Candies
- LeetCode 575. Distribute Candies
- 575. Distribute Candies
- 575. Distribute Candies
- 【Android】不同的View引起软键盘无法关闭问题解决方案
- java线程&&并发-实践笔记
- JNDI详细配置及使用
- 又一段旅程
- bitmap 图像压缩方法
- 575. Distribute Candies
- Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
- Android mdpi hdpi xdpi
- K-means聚类算法
- js对象的深拷贝和浅拷贝
- 程序1--互不重复的三位数
- 阻止a标签默认行为的几种简单方法
- Spring 实现数据库读写分离
- 对你来说,哪一个深度学习网络是最佳选择?(2)