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. Qt5_容器_知识点记录

    1.删除: 1.1.erase 1.2.remove / removeAt 2. 3. 4. 5.

  2. marquee 跑马灯公告

    1.原始 marquee 2.自定义 marquee .tops { color: #fff; height: 23px; margin: 0 0 0 20px; min-height: 23px; ...

  3. JavaScript权威指南--脚本化HTTP

    知识要点 超文本传输协议(HTTP)规定web浏览器如何从web服务器获取文档和向web服务器发送表单内容,以及web服务器如何响应这些请求和提交.web浏览器会处理大量的HTTP.通常,HTTP并不 ...

  4. Unity中的文件

    Unity中的文件大致分为一下几类: 1.资源文件: 导入后,除非是修改,否则不会变化的文件.例如:fbx文件.贴图文件.音频文件.视频文件.动画文件等. 这些文件在导入到Unity的时候,都会进行转 ...

  5. 距离为K的节点 All Nodes Distance K in Binary Tree

    2018-07-26 17:38:37 问题描述: 问题求解: 解法一. 第一种解法是使用Graph + BFS.换言之,就是将二叉树转化为无向图,然后在无向图中使用BFS进行层次遍历即可. 这种解法 ...

  6. C#通过XElement写入XML文件

    首先我们先看一下最终结果,如下: <?xml version="1.0" encoding="utf-8"?> <config> < ...

  7. sql表联接

    1.join: 表:erp_orders和erp_orders_products SELECT * FROM erp_orders_products AS products, erp_orders A ...

  8. 用了皮肤控件之后,报错:容量超出了最大容量 参数名:capacity

    用了皮肤控件之后,报错:容量超出了最大容量 参数名:capacity MessageBox.show()错误!!容量超出了最大容量.参数名: capacity 解决方案: 设置 skin.SkinDi ...

  9. sql server server 2005任务导入导出功能选项没有的解决方法

         出现这个问题主要原因是安装的sql server是Express版本的,或者已经安装了Express版本之后安装了企业版的.但是SQL图形管理工具仍然是SQL Server Manageme ...

  10. 第一个 MVC 应用程序(上半部分)(《精通 ASP.NET MVC5》 的第二章)

    本章将使用 ASP.NET MVC 框架创建一个简单的数据录入应用程序. 笔者会将过程分解成一个个的步骤,以便能够看出如何构造 ASP.NET MVC 应用程序.(对于一些未进行解释的内容,笔者提供了 ...