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"].

Credits:

==============

题目,返回数组范围的  集合.

思路:

模拟整个过程,利用标准库中提供了to_string函数,

就没有什么大问题.

============

code如下:

class Solution {
public:
vector<string> summaryRanges(vector<int>& nums) {
vector<string> re;
if(nums.empty()) return re;
int n = nums.size();
for(int i = ;i<n;){
//string tt = to_string(nums[i]);
string t = to_string(nums[i])+"->";
int j = i+;
while(j<n && nums[j]==nums[j-]+){
j++;
}
if(i==(n-) || j==(i+)){
re.push_back(to_string(nums[i]));
}else{
t+=to_string(nums[j-]);
re.push_back(t);
}
i = j;
}///for
for(auto i:re) cout<<i<<endl;
return re;
}
};

228. Summary Ranges的更多相关文章

  1. leetcode-【中等题】228. Summary Ranges

    题目: 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its r ...

  2. 【LeetCode】228. Summary Ranges 解题报告(Python)

    [LeetCode]228. Summary Ranges 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/sum ...

  3. 【刷题-LeetCode】228. Summary Ranges

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

  4. Java for LeetCode 228 Summary Ranges

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

  5. LeetCode(228) Summary Ranges

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

  6. (easy)LeetCode 228.Summary Ranges

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

  7. 【LeetCode】228 - Summary Ranges

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

  8. Java [Leetcode 228]Summary Ranges

    题目描述: Given a sorted integer array without duplicates, return the summary of its ranges. For example ...

  9. C#解leetcode 228. Summary Ranges Easy

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

随机推荐

  1. 345. Reverse Vowels of a String

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...

  2. CollectionsAPI

    鉴于总用,总结一下: 类别 方法 查找 binarySearch. 返回 enumeration.checkedSortedMap 判断 max.min 移动 reverse(List).revers ...

  3. Soapui 简单学习整理

    post 请求  输入汉字提示错误的问题  ;  如图 将request请求 下的属性 Encoding改为UTF-8

  4. C++ Primer : 第十二章 : 动态内存之shared_ptr类实例:StrBlob类

    StrBlob是一个管理string的类,借助标准库容器vector,以及动态内存管理类shared_ptr,我们将vector保存在动态内存里,这样就能在多个对象之间共享内存. 定义StrBlob类 ...

  5. nginx下的rewrite

    一.正则表达式匹配,其中: * ~ 为区分大小写匹配 * ~* 为不区分大小写匹配 * !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 二.文件及目录匹配,其中: * -f和!-f用来判断是否 ...

  6. Oracle学习系列1

    两个服务必须启动: OracleOraDb10g*TNListener 和 OracleService*** 使用sqlplusw先进行环境的设置 set linesize 300 ; set pag ...

  7. “访问 IIS 元数据库失败”错误的解决方法

    1.依次点击“开始”-“运行”.    2.在“运行”栏内输入 “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i ...

  8. HashMap的原理与实 无锁队列的实现Java HashMap的死循环 red black tree

    http://www.cnblogs.com/fornever/archive/2011/12/02/2270692.html https://zh.wikipedia.org/wiki/%E7%BA ...

  9. LNMP-查看安装编译时参数

    查看mysql编译参数: cat /usr/local/mysql/bin/mysqlbug | grep CONFIGURE_LINE 查看apache编译参数: cat $apachehome$/ ...

  10. 市委组织部考核项目——利用EasyUi中可编辑的DataGrid控件对多行数据进行编辑并提交

    http://blog.csdn.net/cjr15233661143/article/details/19041165 市委组织部考核项目中需要录入原始数据,拿开发区的数据录入举例说明,见下图,需要 ...