public List<String> findMissingRanges(int[] nums, int lower, int upper) {
List<String> result = new ArrayList<>();
int l = 0, r = nums.length;
int start = 0, end = nums.length-1;
while(start < nums.length && nums[start] < lower) start++;
while(end >= 0 && nums[end] > upper) end--;
if(start > end) {
if(upper == lower) result.add("" + upper);
else result.add(lower+"->"+upper);
return result;
}
if((long)nums[start]-lower == 1) result.add(lower+"");
else if((long)nums[start]-lower > 1) result.add(lower + "->" + ((long)nums[start]-1));
for(int i = start; i < end; i++) {
if((long)nums[i]+2 == nums[i+1]) {
result.add(nums[i]+1+"");
} else if((long)nums[i+1]-(long)nums[i] > 2) {
result.add((long)nums[i]+1 + "->" + ((long)nums[i+1]-1));
}
}
if(nums[end] == (long)upper-1) result.add(upper+"");
else if(nums[end] < upper-1) result.add((long)nums[end]+1 + "->" + (upper));
return result;
}