|
| 1 | +<h2><a href="https://leetcode.com/problems/find-missing-elements">4107. Find Missing Elements</a></h2><h3>Easy</h3><hr><p>You are given an integer array <code>nums</code> consisting of <strong>unique</strong> integers.</p> |
| 2 | + |
| 3 | +<p>Originally, <code>nums</code> contained <strong>every integer</strong> within a certain range. However, some integers might have gone <strong>missing</strong> from the array.</p> |
| 4 | + |
| 5 | +<p>The <strong>smallest</strong> and <strong>largest</strong> integers of the original range are still present in <code>nums</code>.</p> |
| 6 | + |
| 7 | +<p>Return a <strong>sorted</strong> list of all the missing integers in this range. If no integers are missing, return an <strong>empty</strong> list.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<div class="example-block"> |
| 13 | +<p><strong>Input:</strong> <span class="example-io">nums = [1,4,2,5]</span></p> |
| 14 | + |
| 15 | +<p><strong>Output:</strong> <span class="example-io">[3]</span></p> |
| 16 | + |
| 17 | +<p><strong>Explanation:</strong></p> |
| 18 | + |
| 19 | +<p>The smallest integer is 1 and the largest is 5, so the full range should be <code>[1,2,3,4,5]</code>. Among these, only 3 is missing.</p> |
| 20 | +</div> |
| 21 | + |
| 22 | +<p><strong class="example">Example 2:</strong></p> |
| 23 | + |
| 24 | +<div class="example-block"> |
| 25 | +<p><strong>Input:</strong> <span class="example-io">nums = [7,8,6,9]</span></p> |
| 26 | + |
| 27 | +<p><strong>Output:</strong> <span class="example-io">[]</span></p> |
| 28 | + |
| 29 | +<p><strong>Explanation:</strong></p> |
| 30 | + |
| 31 | +<p>The smallest integer is 6 and the largest is 9, so the full range is <code>[6,7,8,9]</code>. All integers are already present, so no integer is missing.</p> |
| 32 | +</div> |
| 33 | + |
| 34 | +<p><strong class="example">Example 3:</strong></p> |
| 35 | + |
| 36 | +<div class="example-block"> |
| 37 | +<p><strong>Input:</strong> <span class="example-io">nums = [5,1]</span></p> |
| 38 | + |
| 39 | +<p><strong>Output:</strong> <span class="example-io">[2,3,4]</span></p> |
| 40 | + |
| 41 | +<p><strong>Explanation:</strong></p> |
| 42 | + |
| 43 | +<p>The smallest integer is 1 and the largest is 5, so the full range should be <code>[1,2,3,4,5]</code>. The missing integers are 2, 3, and 4.</p> |
| 44 | +</div> |
| 45 | + |
| 46 | +<p> </p> |
| 47 | +<p><strong>Constraints:</strong></p> |
| 48 | + |
| 49 | +<ul> |
| 50 | + <li><code>2 <= nums.length <= 100</code></li> |
| 51 | + <li><code>1 <= nums[i] <= 100</code></li> |
| 52 | +</ul> |
0 commit comments