五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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ó)家法律
扶绥县| 沙雅县| 山东| 卢湾区| 桐乡市| 江西省| 永嘉县| 牙克石市| 铜川市| 丹寨县| 嘉峪关市| 麻城市| 那坡县| 桐乡市| 涟源市| 新巴尔虎左旗| 子洲县| 壤塘县| 滨海县| 伊宁市| 香河县| 盐津县| 龙游县| 靖远县| 永兴县| 乌海市| 兴业县| 兴业县| 渭南市| 佳木斯市| 永德县| 彰武县| 内江市| 香港| 滁州市| 聂拉木县| 梨树县| 博爱县| 浦县| 同仁县| 车险|