(easy)LeetCode 228.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"].
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
代码如下:
public class Solution {
    public List<String> summaryRanges(int[] nums) {
        List<String>list=new ArrayList<String>();
        int len=nums.length;
        if(len==0) return list;
        int begin=nums[0];
        int end=nums[0];
        for(int i=0;i<len;i++){
            begin=nums[i];
            while(i+1<len && nums[i+1]-nums[i]==1)
                 i++;
            end=nums[i];
            String s=null;
            if(begin!=end)
                 s=""+begin+"->"+end;
            else
                 s=""+begin;
            list.add(s);
        }
        return list;
    }
}
运行结果:

(easy)LeetCode 228.Summary Ranges的更多相关文章
- [LeetCode] 228. Summary Ranges 总结区间
		
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
 - C#解leetcode   228. Summary Ranges  Easy
		
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
 - LeetCode 228. Summary Ranges (总结区间)
		
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
 - Java for LeetCode 228 Summary Ranges
		
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
 - LeetCode(228) Summary Ranges
		
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
 - Java [Leetcode 228]Summary Ranges
		
题目描述: Given a sorted integer array without duplicates, return the summary of its ranges. For example ...
 - [leetcode]228. Summary Ranges区间统计
		
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
 - 【LeetCode】228. Summary Ranges 解题报告(Python)
		
[LeetCode]228. Summary Ranges 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/sum ...
 - leetcode-【中等题】228. Summary Ranges
		
题目: 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its r ...
 
随机推荐
- js列表分页
			
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
 - JavaScript 类定义常用方法(转)
			
1.对象直接量 var obj1 = { v1 : "", get_v1 : function() { return this.v1; }, set_v1 : function(v ...
 - 文件上传工具类 UploadUtil.java
			
package com.util; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ja ...
 - mysql的text的类型注意
			
不要以为text就只有一种类型! Text也分为四种类型:TINYTEXT.TEXT.MEDIUMTEXT和LONGTEXT 其中 TINYTEXT 256 bytes TEXT 65,535 byt ...
 - .NET,Cookie,写Cookie,取Cookie
			
Cookie是一段文本信息,在客户端存储 Cookie 是 ASP.NET 的会话状态将请求与会话关联的方法之一.Cookie 也可以直接用于在请求之间保持数据,但数据随后将存储在客户端并随每个请求一 ...
 - 【jmeter】浅说 think time
			
接口每天被5000个人调用,同时在线500人,每天要被调用50000次. 过了没多久测试完成写了一份报告发给项目经理: 并发 | 响应时间 | 应用服务器cpu |数据库服务器cpu |TPS | ...
 - php 导出csv文件
			
<?php $sql = "select * from members_sqzj order by id asc"; $result = $db->fetch_All( ...
 - 【设计模式】装饰者模式(Decorator)
			
装饰者模式 动态的将责任附加到对象上,若要扩展功能,装饰者提供了比继承更有弹性的替代方案. Java I/O中的装饰类 示例:coffee装饰者模式类图 顶层超类 被装饰组件-被装饰者 装饰者抽象类 ...
 - Python 迭代删除重复项,集合删除重复项
			
1. 迭代删除重复项:先排序列表项,然后通过新迭代(not in)去除重复项,分片打印 def sanitize(time_string): if '-' in time_string: splitt ...
 - [svn]svn conflict 冲突解决
			
转自:http://www.gezila.com/tutorials/17290.html 目录: 1. 同一处修改文件冲突 1.1. 解决方式一 1.2. 解决方式二 1.3. 解决总结 2. 手动 ...