dsa · easy
Summary Ranges
nums is a sorted unique integer array (strictly increasing). Cover it with the fewest contiguous ranges, in order. A run of one value a becomes "a"; a run a, a+1, …, b becomes "a->b".
Arguments
nums— sorted unique integers to cover with "a" / "a->b" ranges
Example
nums = [0,1,2,4,5,7] groups as 0..2, 4..5, and 7 → ["0->2","4->5","7"].
nums = [0,2,3,4,6,8,9] → ["0","2->4","6","8->9"].
An empty array yields [].
Constraints
0 <= nums.length <= 20 -2^31 <= nums[i] <= 2^31 - 1 nums is sorted in non-decreasing order and all values are unique Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [0, 1, 2, 4, 5, 7] Expected: ["0->2","4->5","7"]
Example 2
Input: [0, 2, 3, 4, 6, 8, 9] Expected: ["0","2->4","6","8->9"]