[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 ...
随机推荐
- FastJson之JsonObject, JsonString, JavaBean,List快速转换
// 将json字符串转换为json对象 JSONObject jsonObject = JSON.parseObject(jsonStr); // {"retState":&qu ...
- js 对call apply bind理解
请参考 http://www.cnblogs.com/xljzlw/p/3775162.html 1.call和apply的区别:参数类型不同var mtt = { name: "mtt&q ...
- NotifyIcon实现托盘程序
NotifyIcon 控件的常用属性属性:Icon类型:System.Drawing.Icon说明:将在系统任务栏中显示的图标.可以在设计时指定,也可在运行时动态指定.属性:Text类型:String ...
- php5.4 的 arm 交叉编译
./configure --prefix=/h1root/usr/php --host=arm-linux --enable-libxml --with-mysql=mysqlnd --with-my ...
- git 下载代码
git clone https://github.com/ContextLogic/Wish-Merchant-API.git wish(wish是下载的地址,这样的话,就在你的住文件夹上)
- 37. Sudoku Solver *HARD*
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...
- elasticsearch配置详解
一.说明 使用的是新版本5.1,直接从官网下载rpm包进行安装,https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5 ...
- 禁止一个click事件执行的方法
用jquery点击一次之后,在里面给这个元素加上这个样式,就可以了. 'pointer-events':'none'
- Openwrt working with patches in the build system (8)
Reference :https://openwrt.org/docs/guide-developer/build-system/use-patches-with-buildsystem exampl ...
- Python 字符串转换为字典(String to Dict)
一.需求 为了处理从redis中拿到的value,如下 {"appId":"ct","crawlSts":false,"healt ...