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----myownstars(102)

    http://blog.itpub.net/15480802/cid-84815-list-1/

  2. careercup-递归和动态规划 9.10

    9.10 给你一堆n个箱子,箱子宽w,高h,深d.箱子不能翻转,将箱子堆起来时,下面箱子的宽度.高度和深度必须大于上面的箱子.实现一个方法,搭出最高的一堆箱子,箱堆的高度为每个箱子高度的总和. 解法: ...

  3. debian添加新硬盘

      1.查看硬盘设备,找到要添加的硬盘/dev/sdbfdisk -l 2.创建硬盘分区fdisk /dev/sdb进入到fdisk程序 p 命令显示硬盘的分区表信息n 添加新分区 (1) n 添加新 ...

  4. java class 文件解析

    参考下面两个文章对一个class文件进行解析: http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.6 htt ...

  5. CVPR 2013 录用论文【待更新】

    完整录用论文官方链接:http://www.pamitc.org/cvpr13/program.php 过段时间CvPaper上面应该会有正文链接 今年有关RGB-D摄像机应用和研究的论文渐多起来了. ...

  6. prepare a mysql docker server

    @run server.. docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql @applica ...

  7. web项目设计与开发——DBHelper2

    第二次学习的内容是根据DBHelper遍历出数据库中的所有数据. 具体内容为:   一.编写程序    1.创建工程——userMangager    2.在src目录下创建四个包,分别为DAO,DB ...

  8. 使用modelsim仿真DDR3时编译出错的解决方法

    Modelsim 10.1c release note sates as : Product Changes in 10.1c Release 10.1b introduced a new error ...

  9. UpdateProgress使用

    UpdateProgress是一个进度显示条,加在AJAX里能显得更加的人性化(个人认为).现在我们就开始吧: 第一.新建一个AJAX项目.在页面上加上ScriptManager,UpdatePane ...

  10. u盘的超级用法

    转自360         U盘是大家最常用的移动存储设备,不过它的即插即用特性在给我们带来方便同时,也带来了极大的安全隐患.一款没有加密功能的U盘,在借给他人使用或不慎丢失时,其中所保存的资料将很容 ...