[LeetCode&Python] Problem 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: 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:
- The length of the given array is in range [2, 10,000], and will be even.
- 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的更多相关文章
- 【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 解题报告
题目要求 Given an integer array with even length, where different numbers in this array represent differ ...
- 【leetcode】575. Distribute Candies
原题 Given an integer array with even length, where different numbers in this array represent differen ...
- LeetCode: 575 Distribute Candies(easy)
题目: Given an integer array with even length, where different numbers in this array represent differe ...
- 575. Distribute Candies
https://leetcode.com/problems/distribute-candies/description/ 题目比较长,总结起来很简单:有个整型数组,长度是偶数,把它分成两份,要求有一 ...
- 575. Distribute Candies 平均分糖果,但要求种类最多
[抄题]: Given an integer array with even length, where different numbers in this array represent diffe ...
- [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 ...
- [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.dom设置属性 disabled="disabled" || disabled=true 2.css样式(高版本浏览器) pointer-events:non ...
- MySQL函数GROUP_CONCAT() 实现多条数据合并
group_concat()会计算哪些行属于同一组,将属于同一组的列显示出来,group by指定的列进行分组. 例如: -- 根据物流订单id查询所有物流订单,车源订单,车辆信息(多条数据合并为一条 ...
- Netty优雅退出机制和原理
1.进程的优雅退出 1.1.Kill -9 PID带来的问题 在Linux上通常会通过kill -9 pid的方式强制将某个进程杀掉,这种方式简单高效,因此很多程序的停止脚本经常会选择使用kill - ...
- 雷林鹏分享:C# 集合(Collection)
C# 集合(Collection) 集合(Collection)类是专门用于数据存储和检索的类.这些类提供了对栈(stack).队列(queue).列表(list)和哈希表(hash table)的支 ...
- 什么是SQL游标?
1.1游标的概念 游标(Cursor)它使用户可逐行访问由SQL Server返回的结果集.使用游标(cursor)的一个主要的原因就是把集合操作转换成单个记录处理方式.用SQL语言从数据库中检索数据 ...
- .split(",", -1);和.split(",")的区别
.split(",", -1);和.split(",")的区别在于://eg:String a="河南省,,金水区".//a.split(& ...
- hdu-3980-nim博弈/sg函数
Paint Chain Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 第一个 MVC 应用程序(下半部分)
2.4 创建一个简单的数据录入应用程序 本章的其余部分将通过一个简单的数据录入应用程序来考查 MVC 的更多基本特性.本小节打算分步进行,目的是演示 MVC 的运用. B1.设计一个数据模型 在 MV ...
- POJ 1442 splay
前几天用treap写了这一题,不过treap支持的操作不如splay的多,作为一个完美主义者,重新用splay写了这一题. splay大部分操作可以通过 强大到无与伦比的数据结构splay-tree ...
- svn: E200009: 'lib/systemd/system/dropbear@.service': a peg revision is not allowed here problem
case: svn add lib/systemd/system/dropbear@.service svn: E200009: 'lib/systemd/system/dropbear@.servi ...