[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 ...
随机推荐
- 微信小程序发起支付流程
小程序调起支付API 需要参数 邮件中参数 API参数名 详细说明 APPID appid appid是微信小程序后台APP的唯一标识,在小程序后台申请小程序账号后,微信会自动分配对应的appid,用 ...
- set/multiset_01
按序排列 不能指定插入位置 红黑树变体 不可以直接存取元素(即 无[?]/at(?)操作) 不可以直接修改元素值(用 先删除后添加的方式,达到相同效果) A.头尾 添加/移除 B.随机存取 C.数据存 ...
- input 输入框只能输入纯数字
1.onkeyup = "value=value.replace(/[^\d]/g,'')" 使用 onkeyup 事件,有 bug ,那就是在中文输入法状态下,输入汉字之后直接回 ...
- C语言位域解析&符号位扩展规则
从一个例子说起: int main(void){ union{ int i; struct{ ; ; ; }bits; }num; printf("Input an integer for ...
- Codeforces 855B - Marvolo Gaunt's Ring
855B - Marvolo Gaunt's Ring 思路:①枚举a[j],a[i]和a[k]分别用前缀最小值最大值和后缀最小值和后缀最大值确定. ②dp,dp[i][j]表示到第j为止,前i+1个 ...
- Lua面向对象 --- 多继承
工程目录结构: ParentMother.lua: ParentMother = {} function ParentMother:MortherName() print("Morther ...
- C#中一个简单的匹配16进制颜色的正则测试
using System; using System.Text.RegularExpressions; namespace Test { class Program { //匹配16进制颜色代码的正则 ...
- HTML提交方式post和get区别(实验)
HTML提交方式post和get区别(实验) 一.post和get区别 get提交,提交的信息都显示在地址栏中. post提交,提交的信息不显示地址栏中,显示在消息体中. 二.客户端代码 <!D ...
- java中的static关键字 学习总结
使用static关键字修饰的变量和方法为静态变量.静态方法. 非静态方法可以访问静态变量/方法和非静态变量/方法,但静态方法只能访问静态变量/方法. 可以看到在静态方法中调用非静态变量和非静态方法时, ...
- 读写生信流程必备的 Perl 语法
最早就是写Perl的,后来来到公司转Python,现在又要负责流程了,开始重拾Perl,当然是借鉴别人现有的语法,我再重新组合. 基本语法就不介绍了,参照我之前文章 Perl 模块 use str ...