A range[a,b] is the set of all integers from a to b (inclusive).
Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, each element of nums is covered by exactly one of the ranges, and there is no integer x such that x is in one of the ranges but not in nums.
classSolution { public: vector<string> summaryRanges(vector<int>& nums){ vector<string> ret; int i = 0; int n = nums.size(); while (i < n) { int low = i; i++; while (i < n && nums[i] == nums[i - 1] + 1) { i++; } int high = i - 1; string temp = to_string(nums[low]); if (low < high) { temp.append("->"); temp.append(to_string(nums[high])); } ret.push_back(move(temp)); } return ret; } };