Leetcode学习(30)—— Distribute Candies
来源:互联网 发布:淘宝客服介入电话 编辑:程序博客网 时间:2024/05/21 07:00
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: 3Explanation: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: 2Explanation: 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].
# -*- coding:utf-8 -*-class Solution(object): def distributeCandies(self, candies): return min(len(candies)/2, len(set(candies)))
0 0
- Leetcode学习(30)—— Distribute Candies
- LeetCode——575. Distribute Candies(贪心)
- LeetCode | 575. Distribute Candies
- LeetCode之Distribute Candies
- leetcode 575. Distribute Candies
- [LeetCode]575. Distribute Candies
- LeetCode Distribute Candies
- [leetcode]: 575. Distribute Candies
- [leetcode]575. Distribute Candies
- LeetCode 575. Distribute Candies
- leetcode.575. Distribute Candies
- LeetCode 575. Distribute Candies
- 【LeetCode】575 Distribute Candies
- [LeetCode]575.Distribute Candies
- leetcode 575. Distribute Candies
- LeetCode: 575. Distribute Candies
- LeetCode#575. Distribute Candies
- LeetCode 575. Distribute Candies
- JAVA Split方法,拆分字符串后,去除返回的空值
- 微信JSSDK chooseImage uploadImage 接口 在IOS与安卓的差异
- JavaScript中的 == 与 ===
- p3615_floyd
- 走迷宫(存一下而已)
- Leetcode学习(30)—— Distribute Candies
- java中应用Stack进行算术运算
- Source Insight用法
- 【JAVA面试题系列一】面试题总汇--JAVA基础部分
- iOS性能测试
- linux中一些常用的命令
- mysql中错误:1093-You can’t specify target table for update in FROM clause的解决方法
- c#设计模式==建造者模式
- Windows下Nginx的启动、停止等命令