class Solution {
public:
vector<string> summaryRanges(vector<int>& nums) {
vector<string> ans;
if(nums.size()==0)
return ans;
int left=nums[0];
int right;
string str="";
for(int i=1;i<nums.size();i++)
{
if(nums[i]!=nums[i-1]+1)
{
right=nums[i-1];
str+=to_string(left);
if(left!=right)
{
str+="->";
str+=to_string(right);
}
left=nums[i];
ans.push_back(str);
str="";
}
}
right=nums[nums.size()-1];
str+=to_string(left);
if(left!=right)
{
str+="->";
str+=to_string(right);
}
ans.push_back(str);
return ans;
}
};