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. 20145312 《Java程序设计》第三周学习总结

    20145312 <Java程序设计>第三周学习总结 学习笔记 Chapter 4 4.1类与对象 4.1.1 定义类 1.以服饰设计为例,类定义用class关键词,建立衣服实例要用new ...

  2. Android中C可执行程序编译问题

    make:进入目录'/opt/FriendlyARM/tiny4412/android/android-4.1.2'make: *** 没有规则可以创建“out/target/product/gene ...

  3. markdown工作随笔总结

    1. 锚点 (使用方法和链接很像) ## 目录 1. [命名](#命名) ....... **[返回顶部](#目录)** ## 命名 ###命名原则 可以从返回顶部回到目录,也可以点击目录的命名跳到命 ...

  4. unix_timestamp() 和 from_unixtime()

    unix_timestamp() 将时间转换为时间戳.(date 类型数据转换成 timestamp 形式整数) select unix_timestamp('2016-03-23 11:10:10' ...

  5. Android Device Monitor 文件管理使用的常见问题

    本文参照博客:http://blog.csdn.net/aurorayqz/article/details/65705300.以下是我的实际操作. 1.使用Android Device Monitor ...

  6. 解题报告:codeforce 7C Line

    codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...

  7. P4Lang Repository: Switch

    Github Switch Introduction Structure: +-----+ +-----+ +-----+ +-----+ |App a| |App j| |App n| |App z ...

  8. Docker 推送镜像到 阿里Docker镜像

    登录 阿里云Docker镜像 https://cr.console.aliyun.com 创建一个镜像 成功之后点击  “管理” 阿里有详细的 使用说明 PS : 注意的地方是 sudo docker ...

  9. ”由于没有远程桌面授权服务器可以提供许可证,远程会话被中断“的解决方案

    由于windows server 2012 R2 Datacenter 安装了 远程桌面角色,但是这个角色是120天免费的,需要购买授权的. 解决方案: 删除这个角色,就可以正常进行远程桌面连接了.但 ...

  10. Linux系统非root用户安装perl模块

    非root权限安装perl 在使用Linux或是unix时,perl是一个非常有用的脚本的语言. 关于perl的模块安装,网上也有很多介绍,一方面可以通过不同套件自带的软件安装工具安装,一方面可以通过 ...