vector<string> summaryRanges(vector<int>& nums)
{
int nums_len = nums.size();
vector<string> res;
if (nums_len == )
return res; for (int i = ; i < nums_len;) {
int start = i, end = i;
while (end + < nums_len && nums[end + ] == nums[end] + ) end++;
if (end > start)
res.push_back(to_string(nums[start]) + "->" + to_string(nums[end]));
else
res.push_back(to_string(nums[start]));
i = end + ;
}
return res;
}

【LeetCode 228_数组】Summary Ranges的更多相关文章

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

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

  2. leetcode面试准备:Summary Ranges

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

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

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

  4. LeetCode OJ: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. leetcode-【中等题】228. Summary Ranges

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

  7. LeetCode Monotone Stack Summary 单调栈小结

    话说博主在写Max Chunks To Make Sorted II这篇帖子的解法四时,写到使用单调栈Monotone Stack的解法时,突然脑中触电一般,想起了之前曾经在此贴LeetCode Al ...

  8. 【持续更新】leetcode算法-数组篇

    会在近期陆续地完成数组篇的整理,希望对找工作的小伙伴有所帮助.   1.Two Sum:两数相加为一固定值,求其下标.一次遍历数组,用一个hash表存储已经访问过的数及其下标,对于新访问的数value ...

  9. Missing Ranges & Summary Ranges

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

随机推荐

  1. 验证APNS证书的有效性

    openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert xxx.pem

  2. java中hashSet原理

    转自: http://blog.csdn.net/guoweimelon/article/details/50804799 HashSet是JavaMap类型的集合类中最常使用的,本文基于Java1. ...

  3. MLlib1.6指南笔记

    MLlib1.6指南笔记 http://spark.apache.org/docs/latest/mllib-guide.html spark.mllib RDD之上的原始API spark.ml M ...

  4. 设置oracle编辑的快捷方式

    打开PLSQL Developer: 中文版:[工具]-->[首选项]-->[用户界面]-->[编辑器],在右侧界面往下拉找到[自动替换],点击[编辑],就可以自定义想要的快捷方式了 ...

  5. 20145302张薇《Java程序设计》实验五报告

    20145302张薇 实验五:Java网络编程及安全 实验内容 掌握Socket程序的编写: 掌握密码技术的使用: 设计安全传输系统. 实验要求 基于Java Socket实现安全传输 基于TCP实现 ...

  6. JAVA链接数据库

    链接:http://www.cnblogs.com/centor/p/6142775.html 开发工具: MyEclipse MySQL JDBC驱动:mysql-connector-java-5. ...

  7. 使用WebUploader实现文件批量上传,进度条显示功能

    知识点:利用WebUploader,实现文件批量上传,并且实时显示文件的上传进度 参考官方文档:http://fex.baidu.com/webuploader/ (1)引入三个资源 JS,CSS,S ...

  8. java httpUtil

    public class HttpUtils { public static String getContent(String url, Map<String, String> heads ...

  9. oracle in语句的坑

    oracle 的in语句最多只能有1000条数据,超出,sql报错.

  10. 检签 sub sup应用

    <html> <body> <b>This text is bold</b> <br /> <strong>This text ...