Summary Ranges
Given a sorted array of unique integers, return the minimal list of ranges that cover all numbers.
Examples
Input: [0,1,2,4,5,7]
Output: ["0->2","4->5","7"]
Input: [0,2,3,4,6,8,9]
Output: ["0","2->4","6","8->9"]
Hints
Initialize two pointers, `start` and `end`, both set to the first element of the array. Use `end` to traverse the array and find the longest consecutive sequence.
When a non-consecutive number is encountered (i.e., `nums[i] != nums[i-1] + 1`), close the current range by appending the formatted range to the result list. Update `start` to the current number and reset `end`.
After the loop, ensure the last range is added to the result list by checking if `start` and `end` are still valid (i.e., `start <= end`). Handle edge cases where the array is empty or contains a single element.
Summary Ranges
Given a sorted array of unique integers, return the minimal list of ranges that cover all numbers.