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. 【转】cocos2d-x 模仿计时器效果,动态增加分数——2013-08-25 16

    http://www.cocos2dev.com/?p=90 游戏中要用到分数是动态增加的,而不是瞬间加上去的. bool HelloWorld::init() { if ( !CCLayer::in ...

  2. 配置servers时,错误:Setting property 'source' to 'org.eclipse.jst.jee.server:hczm' did not find a matching property

    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.e ...

  3. css制作小三角

    视觉稿中经常有些小三角,如下图.每次用图片做太不方便了,我们看看用css实现的效果(支持ie6,7哦) <style> /*border实现三角*/ /*箭头向上*/ .arrow-top ...

  4. JVM笔记4:Java内存分配策略

    简单来说,对象内存分配主要是在堆中分配.但是分配的规则并不是固定的,取决于使用的收集器组合以及JVM内存相关参数的设定 以下介绍几条基本规则(使用的ParNew+Serial Old收集器组合): 一 ...

  5. freewrap——将tcl/tk脚本转变为可执行文件

     FreeWrap可以把TCL/TK的脚本和二进制文件打包成应用程序,FreeWrap将所有的文件组合成一个单独的可执行文件.     FreeWrap的原理是把脚本和tcl/tk解释器和库文件都打包 ...

  6. C++ 全排列函数 nyoj 366

    C++ STL中提供了std::next_permutation与std::prev_permutation可以获取数字或者是字符的全排列,其中std::next_permutation提供升序.st ...

  7. 移动端Web页面问题

    1.安卓浏览器看背景图片,有些设备会模糊.   用同等比例的图片在PC机上很清楚,但是手机上很模糊,原因是什么呢? 经过研究,是devicePixelRatio作怪,因为手机分辨率太小,如果按照分辨率 ...

  8. nofollow标签如何使用

    “nofollow”的意思是不传递权重,向网站站长提供了一种方式,即告诉搜索引擎“不要追踪此网页上的链接”或“不要追踪此特定链接”. nofllow的形式 1.<meta name=" ...

  9. Android和.net API的数据交互

    一..net API 一般的页面都是.aspx文件,由于.aspx文件都带有HTML的格式,我们传递的都是json格式的数据,所以html页面格式对json格式有影响,故而我们写Web-API都不会采 ...

  10. 推荐几本C#程序员阅读的书籍

    http://www.cnblogs.com/tongming/p/3879752.html