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

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
庆元县| 博野县| 镇宁| 清水县| 温泉县| 东方市| 南宁市| 彝良县| 夏津县| 建德市| 且末县| 安岳县| 鄂尔多斯市| 望城县| 闽清县| 兴化市| 石首市| 武城县| 浙江省| 顺平县| 乌苏市| 灵川县| 卓资县| 丹凤县| 海伦市| 保德县| 马尔康县| 垣曲县| 洱源县| 若尔盖县| 肥东县| 威信县| 健康| 斗六市| 奉新县| 陇南市| 邢台县| 阳山县| 凤翔县| 静海县| 潜山县|