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

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

LeetCode 2784. Check if Array is Good

2023-07-23 11:43 作者:您是打尖兒還是住店呢  | 我要投稿

You are given an integer array?nums. We consider an array?good?if it is a permutation of an array?base[n].

base[n] = [1, 2, ..., n - 1, n, n]?(in other words, it is an array of length?n + 1?which contains?1?to?n - 1?exactly once, plus two occurrences of?n). For example,?base[1] = [1, 1]?and?base[3] = [1, 2, 3, 3].

Return?true?if the given array is good, otherwise return?false.

Note:?A permutation of integers represents an arrangement of these numbers.

?

Example 1:

Input: nums = [2, 1, 3]

Output: false

Explanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false.

Example 2:

Input: nums = [1, 3, 3, 2]

Output: true

Explanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true.

Example 3:

Input: nums = [1, 1]

Output: true

Explanation: Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.

Example 4:

Input: nums = [3, 4, 4, 1, 2, 1]

Output: false

Explanation: Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false.

?下面是代碼:

Constraints:

  • 1 <= nums.length <= 100

  • 1 <= num[i] <= 200

Runtime:?2 ms, faster than?100.00%?of?Java?online submissions for?Check if Array is Good.

Memory Usage:?41.8 MB, less than?33.33%?of?Java?online submissions for?Check if Array is Good.


LeetCode 2784. Check if Array is Good的評論 (共 條)

分享到微博請遵守國家法律
西乌珠穆沁旗| 茌平县| 城步| 阜宁县| 蕲春县| 成武县| 莱阳市| 唐河县| 阿坝| 凤阳县| 汉川市| 韩城市| 绵竹市| 南陵县| 三江| 吕梁市| 赤水市| 浏阳市| 清徐县| 封丘县| 岳池县| 抚顺县| 明水县| 瓮安县| 盐池县| 集安市| 登封市| 文山县| 二连浩特市| 自贡市| 东乡族自治县| 老河口市| 五寨县| 东台市| 永定县| 资兴市| 赤壁市| 武安市| 巴林左旗| 卢龙县| 汝州市|