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

歡迎光臨散文網(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ó)家法律
普定县| 许昌市| 淮安市| 舟山市| 腾冲县| 城市| 呼和浩特市| 高淳县| 雷波县| 拉萨市| 静宁县| 沙雅县| 古浪县| 嵩明县| 武鸣县| 噶尔县| 永善县| 准格尔旗| 高阳县| 西吉县| 商南县| 肇庆市| 星子县| 任丘市| 巨鹿县| 德令哈市| 宣汉县| 海盐县| 临城县| 蓬溪县| 马鞍山市| 漠河县| 和顺县| 北海市| 花莲县| 南丰县| 富蕴县| 佳木斯市| 盱眙县| 璧山县| 阿克|