All problems

Summary Ranges

Easy · intervals

You are given a list of whole numbers nums, sorted from smallest to largest, with no repeats. Describe it as a list of ranges, where a range is a run of numbers that each are exactly 1 more than the one before.

Return one string per range, in increasing order:

Every number belongs to exactly one range. If nums is empty, return an empty list.

Examples

Example 1

Input: nums = [0, 1, 2, 4, 5, 7]

Output: ["0->2", "4->5", "7"]

0, 1, 2 follow each other, then 4, 5, and 7 stands alone.

Example 2

Input: nums = [-3, -2, -1, 0, 1]

Output: ["-3->1"]

Every number is 1 more than the previous one, so the whole list is a single range.

Example 3

Input: nums = [2, 4, 6]

Output: ["2", "4", "6"]

Constraints