You are given an inclusive range [lower, upper] and a sorted unique integer array nums, where all elements are within the inclusive range.
A number x is considered missing if x is in the range [lower, upper] and x is not in nums.
Return the shortest sorted list of ranges that exactly covers all the missing numbers. That is, no element of nums is included in any of the ranges, and each missing number is covered by one of the ranges.
Input: nums = [-1], lower = -1, upper = -1
Output: []
Explanation: There are no missing ranges since there are no missing numbers.
Constraints:
-109 <= lower <= upper <= 109
0 <= nums.length <= 100
lower <= nums[i] <= upper
All the values of nums are unique.
Solutions
Solution 1: Simulation
Thinking
Report the ranges in \([\textit{lower},\textit{upper}]\) that \(nums\) does not cover. The array is sorted, distinct, and of length at most \(100\), so we simulate the gaps: before the first value, between neighbors, and after the last. A difference greater than \(1\) is a missing range.
We can simulate the problem directly according to the requirements.
The time complexity is \(O(n)\), where \(n\) is the length of the array \(nums\). Ignoring the space consumption of the answer, the space complexity is \(O(1)\).