本文共 367 字,大约阅读时间需要 1 分钟。
题目:(中等)
标签:哈希表、数学
解法 | 时间复杂度 | 空间复杂度 | 执行用时 |
---|---|---|---|
Ans 1 (Python) | O ( N ) O(N) O(N) | O ( N ) O(N) O(N) | 48ms (90.91%) |
Ans 2 (Python) | |||
Ans 3 (Python) |
解法一:
class Solution: def numRabbits(self, answers: List[int]) -> int: count = collections.Counter(answers) ans = 0 for k, v in count.items(): ans += math.ceil(v / (k + 1)) * (k + 1) return ans
转载地址:http://hdzcf.baihongyu.com/