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
            
                

 

posted @ 2018-09-02 10:12  hopskin1  阅读(120)  评论(0编辑  收藏  举报