You are given a sorted array of unique integers `nums`. Cover every number with the smallest sorted list of ranges, where a range [a,b] holds every integer from a to b. Write a range as "a->b" when a != b and as "a" when a == b.
You are given a sorted array of unique integers nums. Cover every number with the smallest sorted list of ranges, where a range [a,b] holds every integer from a to b. Write a range as "a->b" when a != b and as "a" when a == b.
Example 1:
Input: {"nums":[0,1,2,4,5,7]}
Output: ["0->2","4->5","7"]
Constraints:
0≤nums.length≤20
−231≤nums[i]≤231−1
All the values of nums are unique.
nums is sorted in ascending order.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[0,1,2,4,5,7]}
Start with an empty res. Each run of consecutive numbers will become one label in it.
sorted nums: neighbours that differ by 1 chain into one run