[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 ...
随机推荐
- threejs和particles.js
particles.js 在线配置的东西: http://vincentgarreau.com/particles.js/ https://threejs.org/ http://thehuub.co ...
- 20170814xlVBA部分代号收盘价转置
原始数据: 转置效果: Sub TransformData() Dim Rng As Range Dim Arr As Variant Dim Dic As Object Dim dCode As O ...
- 1月28日周日,更新ruby到2.5.0版,rvm更新。
在学习Array的方法的时候,发现文档concat方法可以进行多个数组的添加,而我的不行,猜测是ruby版本没有更新. 查询2.31ruby版本的concat方法,果然和2.5版本的不一样. 于是准备 ...
- Confluence 6 嵌套用户组的备注
潜在的性能影响.启用嵌套用户组可能会减慢用户查找的速度. 在 LDAP 中定义嵌套用户组.在 LDAP 中,一个嵌套用户组是 DN (Distinguished Name)的子用户组,这个字用户组将会 ...
- 1 python基础知识
一.python简介 编译型:将所有的源码先编译成机器型语言,并保存为二进制文件,然后一次性执行c c++ go swift 解释型:将代码一行一行边编译边解释python javascript ph ...
- jenkins+python+kubectl实现批量更新k8s镜像
一.jenkins使用官方镜像(官方镜像默认是jenkins用户,权限太低) 因此通过dockerfile重新改为root启动 FROM jenkins/jenkins:lts MAINTAINER ...
- How to create VO s and VLs dynamically in OAF
I have to create 2 VO objects dynamicaly and created 2 VL's dynamically .I have a static HGrid.and i ...
- python的日志模块logging和syslog
syslog模块是在unix环境下工作的模块,不能用于windows,在windows环境下可以使用logging模块. 一.syslog syslog模块可以用于记录系统运行的信息,这个模块提供的方 ...
- C++实现Vector容器的基本功能
本文只实现了Vector的默认构造函数.赋值构造函数.赋值函数.析构函数.重置空间大小函数和插入函数,权当起到抛砖引玉的作用,其他函数功能的实现可在此基础之上进行拓展. #include <io ...
- 最新小程序教学视频,欢迎加小程序交流群免费获取(微信小程序开发(交流QQ群:604788754)
本群会定期分享在工作中做的一些小程序页面,不懂之处也可以随时咨询,可以互相交流学习. 教学视频直接入群,在群公告中显示,优秀小程序代码在群文件中免费获取. 今日代码小程序首页欢迎页面,效果图如下.代码 ...