首页 > 其他 > 详细

781. Rabbits in Forest

时间:2018-09-02 10:45:14      阅读:195      评论:0      收藏:0      [点我收藏+]
class Solution(object):
    def numRabbits(self, answers):
        """
        :type answers: List[int]
        :rtype: int
        """
        dict={}
        for x in answers:
            if x in dict.keys():
                dict[x]=dict[x]+1
            else:
                dict[x]=1
        cnt=0
        for k in dict.keys():
            v=dict[k]
            if v%(k+1)==0:
                cnt+=v/(k+1)*(k+1)
            else:
                cnt+=v/(k+1)*(k+1)+(k+1)
        return cnt
            
                

 

781. Rabbits in Forest

原文:https://www.cnblogs.com/learning-c/p/9572848.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!