CS、CV、ML

# Leetcode Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges.

For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].

class Solution {
public:
vector<string> summaryRanges(vector<int>& nums) {
vector<string> result;
string temp = "";
char number[10];
bool flag = false;
for(int i=0,j=0; i<nums.size(); i++)
{
sprintf(number,"%d",nums[i]);
temp = temp + number;
while((nums[i+1]-nums[i] == 1)&&(i+1<nums.size()))
{
flag = true;
i++;
}
if(flag)
{
sprintf(number,"%d",nums[i]);
temp = temp + "->" + number;
}
flag = false;
result.push_back(temp);
temp = "";
}
return result;
}
};

#### LeetCode - 228. Summary Ranges - 思路详解- C++

2017-01-13 20:50:21

#### leetcode 228: Summary Ranges

2015-06-26 06:22:18

#### Leetcode_228_Summary Ranges

2015-07-05 11:07:31

#### leetcode 163: Missing Ranges

2014-12-31 09:09:49

#### [leetcode] 163. Missing Ranges 解题报告

2016-03-17 06:53:05

#### Summary Ranges(数组中连续的数字段)

2015-06-26 11:53:18

#### [C语言][LeetCode][228]Summary Ranges

2015-08-16 00:57:13

#### [Leetcode]228. Summary Ranges

2016-07-20 16:41:05

#### [LeetCode] 228. Summary Ranges

2017-07-22 11:36:19

#### [Leetcode] 228. Summary Ranges

2018-07-16 05:04:27