Summary Ranges
Problem statement
You are given an integer array nums sorted in strictly increasing order. Split it into runs of consecutive integers, where each number in a run is exactly one more than the number before it. Make every run as long as it can be, so there are as few runs as possible.
Return one string for each run, in order:
"a->b"for a run that starts ataand ends at a different numberb."a"for a run made of the single numbera.
If nums is empty, return an empty list.
Function
summaryRanges(nums: int[]) → List<String>Examples
Example 1
nums = [-3,-2,-1,4,6,7]return = ["-3->-1","4","6->7"]-3, -2 and -1 are consecutive, so they form "-3->-1". 4 stands alone, because 3 and 5 are missing. 6 and 7 form "6->7".
Example 2
nums = [0,2,4,5]return = ["0","2","4->5"]0 and 2 are each alone, since 1 and 3 are missing. 4 and 5 are consecutive and form "4->5".
Example 3
nums = []return = []There are no numbers, so there are no ranges.
Constraints
0 <= nums.length <= 1000-2^31 <= nums[i] <= 2^31 - 1numsis sorted in strictly increasing order.