国产精品天干天干,亚洲毛片在线,日韩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ó)家法律
临夏市| 苍溪县| 崇阳县| 嵩明县| 石狮市| 沂南县| 上饶县| 攀枝花市| 绥德县| 鄯善县| 建始县| 滨海县| 肥城市| 南丰县| 建湖县| 司法| 微山县| 略阳县| 屏南县| 永靖县| 临夏县| 黑龙江省| 万载县| 霍邱县| 武平县| 乾安县| 嫩江县| 抚宁县| 合川市| 通城县| 日土县| 武邑县| 达州市| 密云县| 拜泉县| 襄垣县| 阳城县| 华容县| 穆棱市| 卢龙县| 大丰市|