leetcode第三题Longest Substring Without Repeating Characters java
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的更多相关文章
- leetcode第三题--Longest Substring Without Repeating Characters
Problem:Given a string, find the length of the longest substring without repeating characters. For e ...
- LeetCode第三题—— Longest Substring Without Repeating Characters(最长无重复子字符串)
题目描述 Given a string, find the length of the longest substring without repeating characters. Example ...
- LeetCode 第 3 题(Longest Substring Without Repeating Characters)
LeetCode 第 3 题(Longest Substring Without Repeating Characters) Given a string, find the length of th ...
- 刷题之路第三题--Longest Substring Without Repeating Characters
问题简介:求给定字符串中最长的字符不重复的字符串的长度 问题详解: 给定一个字符串,寻找给定字符串中包含的最长的字符不重复的字符串的长度 注:答案必须是子字符串,不是子序列 是连续的字符不重复的字符串 ...
- 【LeetCode】3 、Longest Substring Without Repeating Characters
题目等级:Medium 题目描述: Given a string, find the length of the longest substring without repeating chara ...
- Leetcode经典试题:Longest Substring Without Repeating Characters解析
题目如下: Given a string, find the length of the longest substring without repeating characters. Example ...
- LeetCode解题笔记 - 3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- LeetCode(3)Longest Substring Without Repeating Characters
题目: Given a string, find the length of the longest substring without repeating characters. For examp ...
- LeetCode Hash Table 3. Longest Substring Without Repeating Characters
HashMap的应用可以提高查找的速度,键key,值value的使用拜托了传统数组的遍历查找方式,对于判断一个字符或者字符串是否已经存在的问题可以非常好的解决.而本题需要解决的问题就是判断新遍历到的字 ...
随机推荐
- Cocos2D-x培训课程
1.1 Cocos2D-x 什么是cocos2d-x cocos2d-x在游戏开发中的运用 cocos2d-x的几个重要版本特点 iOS环境下搭建cocos2d开发环境 windows平台搭建coco ...
- leecode 每日解题思路 127-Factorial Trailing Zeroes
原题描述: 原题地址: Factorial Trailing Zeroes 题目描述很直接, 给出一个整数N, 求这个N的阶乘后尾有几个零.(要求O(logN)时间复杂度) 个人思路: 一开始,最简单 ...
- css :after和:before
:before是css中的一种伪元素,可用于在某个元素之前插入某些内容.:after是css中的一种伪元素,可用于在某个元素之后插入某些内容. 举例: 1.结合border写个对话框的样式. < ...
- spring quartz的触发器CrontriggerBean配置
每一个quartz的CronTrigger表达式分为七个子表达式,每个子表达式之间用空号分割,分别是:秒 分 时 日 月 星期 年.其中年不是必须的,所以CronTrigger最少有六个子表达式. 每 ...
- selendroid项目实战教程1
selendroid是国内使用非常少的框架.资料也少.刚好公司项目用到,给大家分享下,技术不太行,有错误还望指正. 使用selendroid契机,是公司开发的APP,需要大量捕捉Toast信息.公司的 ...
- jquery click事件的可选参数data的作用
$("#ID").click({x:"value"},function (e) { alert(e.data.x); });
- 如何搭建javaweb 开发环境
一.准备工作: (1) 环境要求: 1.java jdk 2.eclipse--j2ee版 3.tomcat 4.mysql 5.HeidiSQL_7.0 (2)搭建步骤: 1.安装JDK,配置环境变 ...
- 关于安卓应用(APK文件)的二次打包
http://blog.csdn.net/baiyuliang2013/article/details/40426681 很多开发者,不管是个人或是公司都不太注重自己开发的应用的安全性,即是 否会被不 ...
- ios PromiseKit
简介: 高级开发是高度异步的,PromiseKit收集了一些帮助函数,让我们开发过程中使用的典型异步模式更加令人愉悦. 1.通过pod安装promisekit: 2. promise.h介绍 @imp ...
- html-----013----实体字符/HTML URL 编码
<!DOCTYPE> 声明 版本 年份 HTML 1991 HTML+ 1993 HTML 2.0 1995 HTML 3.2 1997 HTML 4.01 1999 XHTML 1.0 ...