Easy c++ answer


  • 0
    C

    '''
    class Solution {
    public:
    vector<string> summaryRanges(vector<int>& nums) {
    vector<string> result;
    for(int i=0; i<nums.size();i++)
    {
    int start = nums[i];
    int end = nums[i];
    for(; i < nums.size()-1; i++)
    {
    if(nums[i]+1 == nums[i+1] || nums[i]+1 == nums[i+1])
    {
    end = nums[i+1];
    }
    else
    break;
    }
    if(end==start)
    {
    result.push_back(to_string(start));
    }
    else
    result.push_back(to_string(start)+"->"+to_string(end));
    }
    return result;
    }
    };
    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.