题目:

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> vecStr;
if(nums.size() == )
{
vecStr.push_back(to_string(nums[]));
return vecStr;
}
for(int i = ; i < nums.size(); ++i)
{
int a = nums[i];
while( i+ < nums.size() && (nums[i+] - nums[i]) == )
{
++i;
}
if(a != nums[i])
{
vecStr.push_back(to_string(a) + "->" + to_string(nums[i]));
}
else if(a == nums[i])
vecStr.push_back(to_string(a));
}
return vecStr;
}
};

[LeetCode228]Summary Ranges的更多相关文章

  1. Leetcode228. Summary Ranges汇总区间

    给定一个无重复元素的有序整数数组,返回数组区间范围的汇总. 示例 1: 输入: [0,1,2,4,5,7] 输出: ["0->2","4->5",& ...

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

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

  3. Missing Ranges & Summary Ranges

    Missing Ranges Given a sorted integer array where the range of elements are [lower, upper] inclusive ...

  4. leetcode面试准备:Summary Ranges

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

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

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

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

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

  7. [Swift]LeetCode228. 汇总区间 | Summary Ranges

    Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...

  8. [LeetCode] Summary Ranges 总结区间

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

  9. Java for LeetCode 228 Summary Ranges

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

随机推荐

  1. ueditor编辑文章时候,复制粘贴内容,原来的图片不能显示

    ueditor编辑文章时候.当现有文章有图片的时候, 再复制粘贴文本进去的时候.里面的图片就不能显示了, 编辑器查看文章Html代码,图片路径显示为:src="http://localhos ...

  2. Remote Desktop Organizer – 管理组织远程桌面 - 小众软件

    http://www.appinn.com/remote-desktop-organizer/

  3. Python内置函数str()和repr()

    内建函数str()和repr() (representation.表达,表示)或反引號操作符(``)能够方便地以字符串的方式获取对象的内容.类型.数值属性等信息. str()函数得到的字符串可读性好( ...

  4. .Net 文本框实现内容提示(仿Google、Baidu)

    原文:.Net 文本框实现内容提示(仿Google.Baidu) 1.Demo下载: 文本框实现内容提示(仿Google.Baidu).rar 2.创建数据库.表(我用的sqlserver2008数据 ...

  5. Nutch+HBase

    Nutch+HBase 当我们为nutch的架构发愁的时候,nutch的开发人员送来了nutchbase.我一些简单的测试表明,在hadoop0.20.1和hbase0.20.2上,稍加修改可以运行起 ...

  6. 啊我V办我偶看篇未改片考i

    http://pan.baidu.com/share/link?shareid=3011665141&uk=338692646&third=15                http ...

  7. WebSocket API

    WebSocket API 这一章介绍如何用WebSocket API来控制协议和创建应用,运用http://websocket.org 提供的现有WebSocket服务器,我们可以收发消息.创建一些 ...

  8. ecshop 浏览历史样式的修改

    ecshop的浏览历史的样式,例如我修改的是只让浏览历史显示浏览历史的商品名称 而不显示浏览历史的商品的价格和图片 首先找到要修改 的文件includes\lib_insert.php 找到函数fun ...

  9. 从PCI上读取数据 线程和定时器效率

    从PCI上读取数据 线程和定时器效率 线程: mythread=AfxBeginThread(StartContinuous,(LPVOID)1,THREAD_PRIORITY_NORMAL,0,CR ...

  10. 设计模式10---设计模式之原型模式(Prototype)

    1.场景模式 考虑这样一个实际应用:订单处理系统 里面有一个保存订单的功能,当产品数量超过1000份以后,拆成两份订单,再超,那么就再拆.直到每份订单不超过1000为止,订单有两种,一个是个人订单,一 ...