781. Rabbits in Forest

Posted learning-c

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了781. Rabbits in Forest相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

781. Rabbits in Forest

781. Rabbits in Forest

[哈希] leetcode 781 Rabbits in Forest

LeetCode781. Rabbits in Forest (Hash Table + Math)

[Math_Medium] 781. Rabbits in Forest

Codeforces 781D Axel and Marston in Bitland 矩阵 bitset