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. linux-memory-buffer-vs-cache

    http://stackoverflow.com/questions/6345020/linux-memory-buffer-vs-cache

  2. mfc开发问题_v1

    1. 设置对话框按钮背景图片? 首先,设置对话框按钮的属性为Bitmap,然后导入资源文件(一个你需要作为背景的小图片),最后在该对话框类的OnInitDialog函数中添加如下代码: //设置对话框 ...

  3. 解决DataTable中的DataColumn类型默认为int类型时, 导致不能修改其列值为其他类型的解决办法

    问题起因: 扔给数据库一条select * from [表名] , 得到一个DataTable, 发现有一列status状态的DataColumn的类型是int,然后我想换成字典表里的文字描述,然后就 ...

  4. JVM笔记7:类加载器

    虚拟机设计团队把类加载阶段中的"通过一个类的全限定名来获取描述此类的二进制字节流"这个动作放到Java虚拟机外部实现,以便让应用程序自己决定如何去获取所需要的类,实现这个动作的代码 ...

  5. I2C Verilog的实现(一)

    <span style="font-size:14px;">`timescale 1ns / 1ps module test( sda ); reg scl; inou ...

  6. webbreswer

    为了帮助网友解决"怎么用C#的webBrowser模拟点击页面上的标签"相关的问题,中国学网通过互联网对"怎么用C#的webBrowser模拟点击页面上的标签" ...

  7. CSS实现背景透明,文字不透明(各浏览器兼容) (转)

    /*CSS*/ .waps{ background:url(07158.bmp) no-repeat top center fixed; width:1004px; text-align:center ...

  8. photoshop 常用快捷键大全

    一.文件新建 CTRL+N打开 CTRL+O 打开为 ALT+CTRL+O关闭 CTRL+W保存 CTRL+S 另存为 CTRL+SHIFT+S另存为网页格式 CTRL+ALT+S打印设置 CTRL+ ...

  9. C# 操作数据库的几种方式(数据库使用SQL SERVER2008)

    一:通过常规 T-SQL 语句 (只写删除操作,其他同理) string strConn = ConfigurationManager.ConnectionStrings["SiteConn ...

  10. Oracle 11g之创建和管理表练习

    创建表: SQL> create table name (empno number(4), ename VARCHAR2(10)); 查看表结构: desc name; SQL> desc ...