Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters.
For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.

采用的是比较笨的遍历方法,time=380ms  可通过,不过还要优化

public class Solution {
public int lengthOfLongestSubstring(String s) {
int length=s.length();
int max=0,index=0,count=1; while(index<length){
if(index+count>=length){
if(max<=count){
max=count;
count=1;
}
break;
}
for(int i=index;i<index+count;i++){
if(s.charAt(index+count)==s.charAt(i)){
index=i+1;
if(max<=count){
max=count;
}
count=0;
break;
}
}
count++;
}
return max; }
}

leetcode第三题Longest Substring Without Repeating Characters java的更多相关文章

  1. leetcode第三题--Longest Substring Without Repeating Characters

    Problem:Given a string, find the length of the longest substring without repeating characters. For e ...

  2. LeetCode第三题—— Longest Substring Without Repeating Characters(最长无重复子字符串)

    题目描述 Given a string, find the length of the longest substring without repeating characters. Example ...

  3. LeetCode 第 3 题(Longest Substring Without Repeating Characters)

    LeetCode 第 3 题(Longest Substring Without Repeating Characters) Given a string, find the length of th ...

  4. 刷题之路第三题--Longest Substring Without Repeating Characters

    问题简介:求给定字符串中最长的字符不重复的字符串的长度 问题详解: 给定一个字符串,寻找给定字符串中包含的最长的字符不重复的字符串的长度 注:答案必须是子字符串,不是子序列 是连续的字符不重复的字符串 ...

  5. 【LeetCode】3 、Longest Substring Without Repeating Characters

    题目等级:Medium 题目描述:   Given a string, find the length of the longest substring without repeating chara ...

  6. Leetcode经典试题:Longest Substring Without Repeating Characters解析

    题目如下: Given a string, find the length of the longest substring without repeating characters. Example ...

  7. LeetCode解题笔记 - 3. Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  8. LeetCode(3)Longest Substring Without Repeating Characters

    题目: Given a string, find the length of the longest substring without repeating characters. For examp ...

  9. LeetCode Hash Table 3. Longest Substring Without Repeating Characters

    HashMap的应用可以提高查找的速度,键key,值value的使用拜托了传统数组的遍历查找方式,对于判断一个字符或者字符串是否已经存在的问题可以非常好的解决.而本题需要解决的问题就是判断新遍历到的字 ...

随机推荐

  1. 数据库Mysql性能优化

    http://www.cnblogs.com/itxiongwei/p/5533995.html

  2. Android 开发第三天

    今天学习的内容

  3. C#汉字转拼音首字母

    输入汉字,提取其首字母: /// <summary> /// 汉字转拼音缩写 /// Code By /// 2004-11-30 /// </summary> /// < ...

  4. nyoj 32 组合数

    组合数 时间限制:3000 ms  |            内存限制:65535 KB 难度:3   描述 找出从自然数1.2.... .n(0<n<10)中任取r(0<r< ...

  5. 自己写的demo---equals()跟==的区别

    package equals; /*public class equals { //基本数据类型跟引用数据类型(复合数据类型), //在引用数据类型中equals方法被重写,一般用来比较内存地址 pu ...

  6. 谨以此错误警醒自己---java.lang.ClassNotFoundException:

    今天在做一个小型的实例,用了面向接口编程,采用了工厂来获取数据源和实例,在从配置文件读取实例时,报了个错误如下图: 于是一个一个的类去找错误,最后也没找到,以为工厂代码出错了,看了好几次也没看出来错误 ...

  7. MVC3中使用AuthorizeAttribute特性来完成登陆权限的验证

    以前判断用户是否登录,判断用户Session是否为空,一般会在这个页面写使用: if (HttpContext.Session.IsNewSession) { //todo Login } 每个需要验 ...

  8. ios NSHashTable & NSMapTable

    在ios开发中大家用到更多的集合类可能是像NSSet或者NSDictionary,NSArray这样的.这里要介绍的是更少人使用的两个类,一个是NSMapTable,另一个是NSHashTable. ...

  9. Ext.Net学习笔记03:Ext.Net MessageBus用法

    发布和订阅消息 Ext.Net MessageBus 的本质是一个消息订阅机制,ExtJS中没有这种机制,所以MessageBus的Ext.Net实现的,但并不是原创,这种功能在dojo中早就实现了, ...

  10. Glibc和GCC,ARM-LINUX-GCC的关系

    看到有些贴子/blog上提到「Glibc编译器」,这是个错误的用语.Glibc不是编译器,Glibc不是编译器,Glibc不是编译器.重要的事情说三遍.GCC才是编译器.