国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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ó)家法律
卢湾区| 门头沟区| 长丰县| 临潭县| 玉龙| 东辽县| 灵石县| 子长县| 化州市| 南岸区| 淮阳县| 石台县| 田东县| 齐河县| 普兰店市| 玛沁县| 阳城县| 平江县| 永安市| 章丘市| 且末县| 嘉兴市| 正蓝旗| 汝阳县| 潜江市| 汾西县| 海丰县| 肥东县| 南漳县| 子长县| 北京市| 日照市| 铁岭市| 青浦区| 阿鲁科尔沁旗| 承德县| 安丘市| 兴安县| 应用必备| 武安市| 郸城县|