|
| 1 | +<p>You are given an integer array <code>nums</code>. We consider an array <strong>good </strong>if it is a permutation of an array <code>base[n]</code>.</p> |
| 2 | + |
| 3 | +<p><code>base[n] = [1, 2, ..., n - 1, n, n] </code>(in other words, it is an array of length <code>n + 1</code> which contains <code>1</code> to <code>n - 1 </code>exactly once, plus two occurrences of <code>n</code>). For example, <code>base[1] = [1, 1]</code> and<code> base[3] = [1, 2, 3, 3]</code>.</p> |
| 4 | + |
| 5 | +<p>Return <code>true</code> <em>if the given array is good, otherwise return</em><em> </em><code>false</code>.</p> |
| 6 | + |
| 7 | +<p><strong>Note: </strong>A permutation of integers represents an arrangement of these numbers.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> nums = [2, 1, 3] |
| 14 | +<strong>Output:</strong> false |
| 15 | +<strong>Explanation:</strong> 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. |
| 16 | +</pre> |
| 17 | + |
| 18 | +<p><strong class="example">Example 2:</strong></p> |
| 19 | + |
| 20 | +<pre> |
| 21 | +<strong>Input:</strong> nums = [1, 3, 3, 2] |
| 22 | +<strong>Output:</strong> true |
| 23 | +<strong>Explanation:</strong> 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.</pre> |
| 24 | + |
| 25 | +<p><strong class="example">Example 3:</strong></p> |
| 26 | + |
| 27 | +<pre> |
| 28 | +<strong>Input:</strong> nums = [1, 1] |
| 29 | +<strong>Output:</strong> true |
| 30 | +<strong>Explanation:</strong> 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.</pre> |
| 31 | + |
| 32 | +<p><strong class="example">Example 4:</strong></p> |
| 33 | + |
| 34 | +<pre> |
| 35 | +<strong>Input:</strong> nums = [3, 4, 4, 1, 2, 1] |
| 36 | +<strong>Output:</strong> false |
| 37 | +<strong>Explanation:</strong> 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. |
| 38 | +</pre> |
| 39 | + |
| 40 | +<p> </p> |
| 41 | +<p><strong>Constraints:</strong></p> |
| 42 | + |
| 43 | +<ul> |
| 44 | + <li><code>1 <= nums.length <= 100</code></li> |
| 45 | + <li><code>1 <= num[i] <= 200</code></li> |
| 46 | +</ul> |
0 commit comments