ranges
to store the result.i
to iterate over the elements of nums
.start = nums[i]
.nums[i + 1]
is consecutive to nums[i]
. If so, increment i
by 1.start
is equal to nums[i]
. If true, add start
as a string to ranges
. Otherwise, add the string start->nums[i]
to ranges
.i
by 1 to start a new range.ranges
list.