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

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

分享到微博請遵守國家法律
景德镇市| 北流市| 湘乡市| 渭南市| 海兴县| 太仆寺旗| 翼城县| 陕西省| 蒲江县| 顺平县| 彰化县| 龙海市| 金门县| 寿阳县| 肇庆市| 北安市| 抚顺市| 三门县| 湟中县| 枣庄市| 华亭县| 泗水县| 武强县| 武宣县| 宜兴市| 石门县| 鄯善县| 沁阳市| 福清市| 来宾市| 屯留县| 寿光市| 荣昌县| 荥经县| 拜泉县| 南京市| 曲水县| 商南县| 赫章县| 镇康县| 崇信县|