[LeetCode228]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> 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的更多相关文章
- Leetcode228. Summary Ranges汇总区间
给定一个无重复元素的有序整数数组,返回数组区间范围的汇总. 示例 1: 输入: [0,1,2,4,5,7] 输出: ["0->2","4->5",& ...
- leetcode-【中等题】228. Summary Ranges
题目: 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its r ...
- Missing Ranges & Summary Ranges
Missing Ranges Given a sorted integer array where the range of elements are [lower, upper] inclusive ...
- leetcode面试准备:Summary Ranges
1 题目 Given a sorted integer array without duplicates, return the summary of its ranges. For example, ...
- 【LeetCode】228. Summary Ranges 解题报告(Python)
[LeetCode]228. Summary Ranges 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/sum ...
- 【刷题-LeetCode】228. Summary Ranges
Summary Ranges Given a sorted integer array without duplicates, return the summary of its ranges. Ex ...
- [Swift]LeetCode228. 汇总区间 | Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- [LeetCode] Summary Ranges 总结区间
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- Java for LeetCode 228 Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
随机推荐
- C语言文件操作之fgets()
来说一说fgets(..)函数. 原型 char * fgets(char * s, int n,FILE *stream); 參数: s: 字符型指针, ...
- iOS 单元測试之XCTest具体解释(一)
原创blog,转载请注明出处 blog.csdn.net/hello_hwc 欢迎关注我的iOS-SDK具体解释专栏 http://blog.csdn.net/column/details/huang ...
- hdu5119(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5119 分析:dp[i][j]表示由前i个数组成异或和为j的方法数,则dp[i][j]=d[i-1][j ...
- Beijing Perl Workshop - Augest 10th, 2013
Beijing Perl Workshop - Augest 10th, 2013 Beijing Perl Workshop
- ARM裸编程系列---UART
S5PV210 UART说明 通用异步收发器缩写UART,这是UNIVERSAL ASYNCHRONOUS RECEIVER AND TRANSMITTER.它被用来传送串行数据.当发送数据,CPU将 ...
- 什么样的企业造什么样的软件最easy成功?
事件1: 一般软件企业按功能分,大体分业务应用型软件和系统工具型软件. 按市场分,应用型软件企业较多,直接贴近生活:系统工具类较少,间接贴近大众较少. 事件2: 软件企业中,当中中小型企业老板存在非常 ...
- pcie inbound、outbound及EP、RC间的互相訪问
Inbound:PCI域訪问存储器域 Outbound:存储器域訪问PCI域 RC訪问EP: RC存储器域->outbound->RC PCI域->EP PCI域->inbou ...
- OSGI学习总结
最近的一项研究了解了一下OSGI技术,感觉OSGI尽管有一定的学习难度.可是终于掌握和推广之后将是一项对系统开发比較实用的技术.在此和大家分享一下自己的感悟. 1.什么是OSGI OSGI直译为&qu ...
- Windows Phone开发(2):竖立自信,初试锋茫
原文:Windows Phone开发(2):竖立自信,初试锋茫 上一篇文章中,我们聊了一些"大炮"话题,从这篇文章开始,我们一起来学习WP开发吧. 一.我们有哪些装备. 安装完VS ...
- Vector Clock理解
背景近期在重读"Dynamo: Amazon's Highly Available Key-value Store"(经典好文,推荐!).文章4.4 中聊到了Data Versio ...