This idea is to find the the intervals with continuous discrete numbers like `[1, 2, 3]`

or `[7, 8, 9]`

in `[1, 2, 3, 7, 8, 9]`

. And then we can summarize the interval with the begin number and the end number. This problem is somehow like `truncate the words from one string`

or `find the length of the Nth word in a sentence`

.

**Here is the algorithm:**

- Set
`bgn`

to the current index iterator`i`

. - While
`nums[i + 1] == nums[i]`

then`i++`

; - If
`i != bgn`

which means we have more then one element in this sub interval, otherwise, we have a one-element interval.

**Code:**

```
vector<string> summaryRanges(vector<int>& nums)
{
vector<string> res;
if (nums.empty())
return res;
int i = 0;
while (i < nums.size())
{
int bgn = i;
while (i + 1 < nums.size() and nums[i + 1] == nums[i] + 1)
i++;
if (bgn != i)
{
stringstream ss;
ss << nums[bgn] << "->" << nums[i];
res.push_back(ss.str());
}
else
{
res.push_back(std::to_string(nums[bgn]));
}
i++;
}
return res;
}
```