题目要求

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. 【Android】Android输入子系统

    成鹏致远 | lcw.cnblogs.com | 2013-10-25 Linux输入子系统回顾 1:为什么要回顾linux输入子系统?这个问题后面自然就知道了 1.linux输入子系统设备是基于平台 ...

  2. 浅析tornado 中demo的 blog模块

    #!/usr/bin/env python # # Copyright 2009 Facebook # # Licensed under the Apache License, Version 2.0 ...

  3. Brainfuck反汇编(Python)

    global cs global ip global ss #global sp global ds global bp global tab global out #cs='++++++++++[& ...

  4. Android自动化测试之Monkeyrunner从零开始

    最近由于公司在组织一个Free CoDE的项目,也就是由大家自己选择研究方向来做一些自己感兴趣的研究.由于之前我学过一点点关于android的东西,并且目前android开发方兴未艾如火如荼,但自动化 ...

  5. hdoj:2028

    #include <iostream> using namespace std; int main() { int n, i; ]; while (cin >> n) { in ...

  6. opencv之内存存储器——CvMemStorage与CvSeq

    1.CvMemStorage *storage=cvCreateMemStorage(block_size); 用来创建一个内存存储器,来统一管理各种动态对象的内存. 函数返回一个新创建的内存存储器指 ...

  7. 转:【WebView的cookie机制 】轻松搞定WebView cookie同步问题

    原文链接:http://blog.csdn.net/fengyuzhengfan/article/details/51517622 在进行APP+H5混合开发的时候,一些功能是用native方法实现的 ...

  8. mysql 常用语句集

    1.查询某数据库大小语句: SELECT CONCAT(ROUND(SUM(DATA_LENGTH/1024/1024),2),'MB') AS DATA  FROM TABLES WHERE tab ...

  9. IntelliJ IDEA下spring boot项目打包

    Spring Boot自带Tomcat插件,可以直接编写启动类,开启Tomcat服务 springboot适合前后端分离,打成jar进行部署更合适 application.properties配置端口 ...

  10. fiddler工作原理和代理设置

    1,什么是Fiddler Fiddler是一个http协议调试代理工具,它能够记录客户端和服务器之间的所有 HTTP请求,可以针对特定的HTTP请求,分析请求数据.设置断点.调试web应用.修改请求的 ...