-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path228.cpp
More file actions
29 lines (26 loc) · 671 Bytes
/
Copy path228.cpp
File metadata and controls
29 lines (26 loc) · 671 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//
// 228.cpp
// leetcode
//
// Created by R Z on 2018/4/8.
// Copyright © 2018年 R Z. All rights reserved.
//
#include <stdio.h>
#include <vector>
#include <string>
using namespace std;
class Solution {
public:
vector<string> summaryRanges(vector<int>& nums) {
int len = nums.size();
vector<string> res;
if(len==0) return res;
for(int i=0;i<len;i++){
int tmp = nums[i];
while(i+1<len && nums[i]+1==nums[i+1]) i++;
if(tmp!=nums[i]) res.push_back(to_string(tmp)+"->"+to_string(nums[i]));
else res.push_back(to_string(tmp));
}
return res;
}
};