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: 3
Explanation:
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: 2
Explanation: 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.

Note:

  1. The length of the given array is in range [2, 10,000], and will be even.
  2. The number in given array is in range [-100,000, 100,000].
class Solution:
def distributeCandies(self, candies):
"""
:type candies: List[int]
:rtype: int
"""
n=len(candies)
half=n/2
nu=len(set(candies))
if half>=nu:
return int(nu)
else:
return int(half)

  

[LeetCode&Python] Problem 575. Distribute Candies的更多相关文章

  1. 【LeetCode】575. Distribute Candies 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...

  2. LeetCode 575. Distribute Candies (发糖果)

    Given an integer array with even length, where different numbers in this array represent different k ...

  3. LeetCode 575 Distribute Candies 解题报告

    题目要求 Given an integer array with even length, where different numbers in this array represent differ ...

  4. 【leetcode】575. Distribute Candies

    原题 Given an integer array with even length, where different numbers in this array represent differen ...

  5. LeetCode: 575 Distribute Candies(easy)

    题目: Given an integer array with even length, where different numbers in this array represent differe ...

  6. 575. Distribute Candies

    https://leetcode.com/problems/distribute-candies/description/ 题目比较长,总结起来很简单:有个整型数组,长度是偶数,把它分成两份,要求有一 ...

  7. 575. Distribute Candies 平均分糖果,但要求种类最多

    [抄题]: Given an integer array with even length, where different numbers in this array represent diffe ...

  8. [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...

  9. [LeetCode&Python] Problem 387. First Unique Character in a String

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

随机推荐

  1. Python day4_list的常见方法1_笔记(浅拷贝和深拷贝的简述)

    li=[1,2,3,'55dd'] li.clear()#清除列表内容 print(li) li.append(1)#追加 li.append(3) print(li) #拓展:直接赋值和copy和d ...

  2. 深入Animation,在SurfaceView中照样使用Android—Tween Animation!

    第一类:Frame By Frame 帧动画( 不推荐游戏开发中使用)             所谓帧动画,就是顺序播放事先做好的图像,类似于放电影:             分析: 此种方式类似我之 ...

  3. Linux常用命令 查找文件

    Linux搜索命令:find / -name 'nginx'  搜索根目录下文件名为‘nginx’的文件夹 .find / -name 'nginx.conf' 搜索根目录下文件名为‘nginx.co ...

  4. Codeforces 595D - Max and Bike

    595D - Max and Bike 思路:开始和结束时的计时器的高度相同时(也就是关于圆竖着直径对称)时间最少. 证明: 总距离为d. 圆周长为s=2*π*r. 设len=d-floor(d/s) ...

  5. typescripts学习

    可选与默认参数 可选参数:在参数名后面,冒号前面添加一个问号,则表明该参数是可选的.如下代码: function buildName(firstName: string, lastName?: str ...

  6. javascript对象使用总结

    javascript对象使用总结 一.总结 一句话总结:js对象的主要知识点是创建对象和继承,并且创建对象和继承的方法都是逐步层层递进的 创建对象 继承 原型 创建对象 1 <script> ...

  7. 总是有个yumBackend.py阻止我用yum进行更新

    [Another app is currently holding the yum lock; waiting for it to exit...] 上网查了,好像是说帮我安个桌面图标的进程. 估计是 ...

  8. (转)TeamViewer三种许可证的区别是什么?

    xu言: 这几天在使用teamview对它的许可证做了一些了解,看到这个好像是官方的写的挺不错.留作收藏 PS:https://www.uret.in/  顺便也发现了一个不错的网站 很多想要购买Te ...

  9. IDEA设置类、方法注释模板

    类注释模板 File -> Other Setting -> Default Setting打开默认设置 Editor -> File and Code Templates -> ...

  10. gradle 编译 No such property: sonatypeUsername错误解决

    No such property: sonatypeUsername for class: org.gradle.api.publication.maven.internal.ant.DefaultG ...