最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

leetcode.781. Rabbits in Forest

2022-11-20 19:02 作者:您是打尖兒還是住店呢  | 我要投稿

There is a forest with an unknown number of rabbits. We asked n rabbits?"How many rabbits have the same color as you?"?and collected the answers in an integer array?answers?where?answers[i]?is the answer of the?ith?rabbit.

Given the array?answers, return?the minimum number of rabbits that could be in the forest.

?

Example 1:

Input: answers = [1,1,2]Output: 5Explanation:The two rabbits that answered "1" could both be the same color, say red. The rabbit that answered "2" can't be red or the answers would be inconsistent. Say the rabbit that answered "2" was blue. Then there should be 2 other blue rabbits in the forest that didn't answer into the array. The smallest possible number of rabbits in the forest is therefore 5: 3 that answered plus 2 that didn't.

Example 2:

Input: answers = [10,10,10]Output: 11

?

Constraints:

  • 1 <= answers.length <= 1000

  • 0 <= answers[i] < 1000


具體分析

分析說(shuō)每個(gè)數(shù)字的兔子的數(shù)量,比如說(shuō)1的兔子只有1個(gè)的話,那么這個(gè)顏色的兔子最多就是2個(gè)。說(shuō)1的兔子有2個(gè)的話,也是最多2個(gè),但是有3個(gè)的話,兔子最多就是4個(gè)。所以這時(shí)候,我們要判斷說(shuō)的數(shù)量跟n+1的值對(duì)比,除余之后是0的話,那么兔子的數(shù)量就是商*(數(shù)量+1);

還好一次過(guò)了。


Runtime:?10 ms, faster than?20.77%?of?Java?online submissions for?Rabbits in Forest.

Memory Usage:?43.2 MB, less than?18.42%?of?Java?online submissions for?Rabbits in Forest.


leetcode.781. Rabbits in Forest的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
临泽县| 厦门市| 克山县| 来宾市| 玉溪市| 龙泉市| 武陟县| 巩留县| 鲁山县| 宝鸡市| 任丘市| 永靖县| 隆回县| 库尔勒市| 怀远县| 如东县| 铁岭市| 临桂县| 子洲县| 奇台县| 翁牛特旗| 连州市| 洛扎县| 海淀区| 桐城市| 微博| 涞源县| 沈阳市| 闸北区| 威宁| 平谷区| 临泉县| 襄汾县| 永吉县| 岢岚县| 买车| 吉木乃县| 博乐市| 阿克| 达日县| 宜章县|