Given a sorted integer array where the range of elements are in the inclusive range [lower, upper], return its missing ranges.
Example
Example 1
Input:
nums = [0, 1, 3, 50, 75], lower = 0 and upper = 99
Output:
["2", "4->49", "51->74", "76->99"]
Explanation:
in range[0,99],the missing range includes:range[2,2],range[4,49],range[51,74] and range[76,99]
Example 2
Input:
nums = [0, 1, 2, 3, 7], lower = 0 and upper = 7
Output:
["4->6"]
Explanation:
in range[0,7],the missing range include range[4,6]
分析
这道题是一道easy难度的题目,主要就是要注意int的边界的情况。我们使用一个值lastMin记录当前最小的应该值,遍历nums,如果nums[i] == lastMin, 则lastMin = nums[i] + 1;如果nums[i] > lastMin,说明有空缺,就记录下[lastMin, nums[i] -1]。根据lastMin是