题目要求

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. Asp.Net WebApi学习教程之增删改查

    webapi简介 在asp.net中,创建一个HTTP服务,有很多方案,以前用ashx,一般处理程序(HttpHandler),现在可以用webapi 微软的web api是在vs2012上的mvc4 ...

  2. json-server 详解

    JSON-Server 是一个 Node 模块,运行 Express 服务器,你可以指定一个 json 文件作为 api 的数据源. 安装json-server npm install -g json ...

  3. InstallShield: 1628 完成基于脚本的安装失败

    问题: 第一次卸载程序失败,以后每次卸载出现1628 完成基于脚本的安装失败,使用安装包打开也会出现相同问题. 原因: 首先检查安装包是否出错,然后检查卸载脚本是否出错. InstallShield程 ...

  4. IOS Swift 训练

    // Playground - noun: a place where people can play import Cocoa var str = "Hello, playground&q ...

  5. 树莓派设置静态IP地址

    树莓派设置静态IP地址http://www.jianshu.com/p/b0e6d066d6b6 ——————————————————————————————————————————————————— ...

  6. Java知多少(56)线程模型

    Java运行系统在很多方面依赖于线程,所有的类库设计都考虑到多线程.实际上,Java使用线程来使整个环境异步.这有利于通过防止CPU循环的浪费来减少无效部分. 为更好的理解多线程环境的优势可以将它与它 ...

  7. python一天一题(3)

    #--coding=utf8-- from selenium import webdriver import time import logging import os.path ''' 搜索取搜索的 ...

  8. [PGM] Variable elimination and Belief propagation

    内容范围如题.Lec 08-11的内容:https://www.youtube.com/watch?v=Qa04kw1gKHk&index=36&list=PLQiVpyxVlLkbp ...

  9. [TensorBoard] *Cookbook - Tensorboard

    Ref: https://www.tensorflow.org/get_started/summaries_and_tensorboard 可视化对于Training的重要性,不言而喻. 代码示范 # ...

  10. linux中free命令内存分析

    Mem(物理内存分配情况)行 total:表示物理 内存总量 used:表示总计分配给缓存(包含buffers 与cache )使用的数量,但其中可能部分缓存并未实际使用 free:未被分配的内存 s ...