当前位置:网站首页>Summary ranges of leetcode topic resolution
Summary ranges of leetcode topic resolution
2022-06-23 08:39:00 【ruochen】
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".
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
public List<String> summaryRanges(int[] nums) {
List<String> rt = new ArrayList<String>();
if (nums == null || nums.length == 0) {
return rt;
}
for (int i = 0; i < nums.length; i++) {
int st = nums[i];
int ed = st;
while (i + 1 < nums.length && nums[i + 1] - ed == 1) {
i++;
ed++;
}
if (ed == st) {
rt.add(st + "");
} else {
rt.add(st + "->" + ed);
}
}
return rt;
}边栏推荐
- 论文阅读【Quo Vadis, Action Recognition? A New Model and the Kinetics Dataset】
- Single core driver module
- 1-gradients, shadows, and text
- Spirit matrix for leetcode topic analysis
- Why use growth neural gas network (GNG)?
- 十多年前的入职第一天
- 你有一串代码,但是不支持低版本Go时;判断Go版本号,您值得拥有!
- Leetcode topic analysis spiral matrix II
- 9 ways in which network security may change in 2022
- 6-shining laser application of calayer
猜你喜欢

The rtsp/onvif protocol video platform easynvr startup service reports an error "service not found". How to solve it?

Install a WGet for your win10

jmeter压测结果分析

Why use growth neural gas network (GNG)?

Data assets are king, analyzing the relationship between enterprise digital transformation and data asset management

最常用的5中流ETL模式

Qualcomm 9x07 two startup modes

十多年前的入职第一天

Deep learning ----- different methods to realize vgg16

高通9x07两种启动模式
随机推荐
Deep learning ----- different methods to implement lenet-5 model
Vulnhub | DC: 4 | [combat]
Map (set) operation in go language
Can portals be the next decentraland?
Idea true permanent activation method and permanent activation code tutorial
3-ProgressBar和二次裁剪
Object.defineProperty() 和 数据代理
6-shining laser application of calayer
Hongmeng reads the resource file
Go 数据类型篇(三)之整型及运算符
How to evaluate code quality
Lightweight UI control library worth collecting
There are some limitations in cluster expansion and contraction
Observer mode
Dongyuhui, the "square face teacher", responded that the popularity was declining: do a good job of live broadcasting of agricultural products to benefit farmers and consider supporting education
Basic use of check boxes and implementation of select all and invert selection functions
Driver Architecture & platform platform bus driver model
渲染效果图哪家好?2022最新实测(四)
[cross border e-commerce solutions] lighthouse will be used for pure IP expansion of new business - continuous efforts!
How to restore visualizations and dashboards after kibana rebuilds the index