题目要求

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.

题目分析及思路

给定一个长度为偶数的整数数组,其中不同数字代表不同种类的糖果,且一个数字代表一颗该种糖果。需要将这些糖果平均分给男生和女生,要求返回女生能得到糖果种类的最大值。可以先利用集合特性获得糖果种类数及女生数量,若种类数少于女生数量,则返回种类数;否则返回女生数量。

python代码

class Solution:

def distributeCandies(self, candies: List[int]) -> int:

candy_kinds = len(set(candies))

bro_or_sis_num = len(candies)//2

if candy_kinds < bro_or_sis_num:

return candy_kinds

else:

return bro_or_sis_num

LeetCode 575 Distribute Candies 解题报告的更多相关文章

  1. 【LeetCode】575. Distribute Candies 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...

  2. LeetCode 575. Distribute Candies (发糖果)

    Given an integer array with even length, where different numbers in this array represent different k ...

  3. LeetCode: 575 Distribute Candies(easy)

    题目: Given an integer array with even length, where different numbers in this array represent differe ...

  4. LeetCode 1 Two Sum 解题报告

    LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...

  5. 【LeetCode】Permutations II 解题报告

    [题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...

  6. 【LeetCode】Island Perimeter 解题报告

    [LeetCode]Island Perimeter 解题报告 [LeetCode] https://leetcode.com/problems/island-perimeter/ Total Acc ...

  7. 【LeetCode】01 Matrix 解题报告

    [LeetCode]01 Matrix 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/01-matrix/#/descripti ...

  8. 【LeetCode】Largest Number 解题报告

    [LeetCode]Largest Number 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/largest-number/# ...

  9. 【LeetCode】Gas Station 解题报告

    [LeetCode]Gas Station 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/gas-station/#/descr ...

随机推荐

  1. oracle删除数据库中的所有表

    连接:http://linben.blog.51cto.com/6205951/1293619 1.先禁用数据库中所有的约束 select 'alter table ' || table_name | ...

  2. Spring Session Redis

    http://www.infoq.com/cn/articles/Next-Generation-Session-Management-with-Spring-Session

  3. composer 再centos 下的安装

    $ curl -sS https://getcomposer.org/installer | php $ sudo mv composer.phar /usr/local/bin/composer

  4. CodeIgniter中使用CSRF TOKEN的一个坑

    事情的经过是这样的,一个自动化扫描工具说我的代码中存在XSS漏洞,什么是XSS不懂的朋友可以看这里 我的代码里面开启CodeIgniter框架的CSRF Token,如下: 很简单,更多详情参考CI官 ...

  5. (笔记)AT91SAM9260的启动过程详细解说

    Bootstrap的启动过程 一. 说明: Bootstrap启动代码是官方提供的一级启动代码,包括汇编和C语言两部分组成.对AT91SAM9260来说编译完成后,代码长度必须小于4KB,烧写到dat ...

  6. SpringMVC注解@RequestParam与RequestMapping全面解析

    1.@RequestParam用法: SpringMVC后台控制层获取参数的方式主要有两种, 一种是request.getParameter("name"), 另外一种是用注解@R ...

  7. 【zheng环境准备】安装redis

    1.下载源码,解压缩后编译源码 wget http://download.redis.io/release/redis-2.8.3.tar.gz tar -xzf redis-.tar.gz cd r ...

  8. 跟bWAPP学WEB安全(PHP代码)--终结篇:文件目录遍历、文件上传、SSRF、CSRF、XXE、文件包含

    前言 过年过的很不顺,家里领导和我本人接连生病,年前腊月29才都治好出院,大年初六家里的拉布拉多爱犬又因为细小医治无效离开了,没能过年回家,花了好多钱,狗狗还离世了.所以也就没什么心思更新博客.今天初 ...

  9. callback 模式

    回调,是一种机制,同时也是一种设计模式. 我们定义一个函数,让能够回调 import _products from './products.json' const TIMEOUT = 100 cons ...

  10. Thrift IDL

    Thrift类型 Thrift类型系统旨在允许程序员尽可能使用本机类型,无论使用何种编程语言.此信息基于并取代Thrift白皮书中的信息.Thrift IDL为每一种目标语言提供了用于生成代码的类型描 ...