class Solution {
public:
vector<string> summaryRanges(vector<int>& nums) {
int l = 0;
int r = 0;
vector<string> result;
while (r < nums.size()) {
// find interval
while (r + 1 < nums.size() && nums[r] + 1 == nums[r+1]) {
r++;
}
// save result
if (l != r) {
result.push_back(to_string(nums[l]) + "->" + to_string(nums[r]));
} else {
result.push_back(to_string(nums[l]));
}
// update l, r
r = r + 1;
l = r;
}
return result;
}
};