leetCode刷题(找到最长的连续不重复的字符串长度)
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequenceand not a substring.
/**
* @param {string} s
* @return {number}
*/
var lengthOfLongestSubstring = function(s) {
//这道题是为了找到最长的连续不重复的字符串长度
//可以先过滤掉所有的不重复字符串
var i,j=0;
var lastStr="";
var maxLength=0;
for(i=0;i<s.length;){
if(lastStr.indexOf(s[i])==-1){
lastStr=lastStr.concat(s[i++])
maxLength=Math.max(maxLength,i-j);
}else{
lastStr=lastStr.slice(1);
j++;
}
}
return maxLength;
};
leetCode刷题(找到最长的连续不重复的字符串长度)的更多相关文章
- leetCode刷题(找到最长的回文字符串)
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- C#LeetCode刷题之#674-最长连续递增序列( Longest Continuous Increasing Subsequence)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3734 访问. 给定一个未经排序的整数数组,找到最长且连续的的递增 ...
- LeetCode刷题-005最长回文子串
给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为1000.示例 1:输入: "babad"输出: "bab"注意: "ab ...
- leetcode刷题五<最长回文子串>
下面是题目的描述 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 . 示例 : 输入: "babad" 输出: "bab" 注意: ...
- C#LeetCode刷题之#594-最长和谐子序列(Longest Harmonious Subsequence)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3800 访问. 和谐数组是指一个数组里元素的最大值和最小值之间的差 ...
- C#LeetCode刷题之#521-最长特殊序列 Ⅰ(Longest Uncommon Subsequence I)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3949 访问. 给定两个字符串,你需要从这两个字符串中找出最长的特 ...
- C#LeetCode刷题之#581-最短无序连续子数组( Shortest Unsorted Continuous Subarray)
问题 给定一个整数数组,你需要寻找一个连续的子数组,如果对这个子数组进行升序排序,那么整个数组都会变为升序排序. 你找到的子数组应是最短的,请输出它的长度. 输入: [2, 6, 4, 8, 10, ...
- C#LeetCode刷题之#409-最长回文串(Longest Palindrome)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3788 访问. 给定一个包含大写字母和小写字母的字符串,找到通过这 ...
- C#LeetCode刷题之#14-最长公共前缀(Longest Common Prefix)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3921 访问. 编写一个函数来查找字符串数组中的最长公共前缀. 如 ...
随机推荐
- Linux Android 多点触摸协议 原文出自【比特网】,转载请保留原文链接:http://soft.chinabyte.com/os/71/12306571.shtml
为了使用功能强大的多点触控设备,就需要一种方案去上报用户层所需的详细的手指触摸数据.这个文档所描述的多点触控协议可以让内核驱动程序向用户层上报任意多指的数据信息. 使用说明 单点触摸信息是以ABS承载 ...
- linux 下启动java jar包 shell
linux 下启动java jar包 shell #!/bin/sh JAVA_HOME=/usr/local/jdk1.6.0_34/bin/javaJAVA_OPTS="-Xmx256m ...
- EBS Concurrent Manager(并发管理器)异常处理[final]
来自:http://blog.itpub.net/35489/viewspace-742191/ 有时候我们在通过 adstpall.sh 关闭应用后,然后再使用adstrtal.sh开启.发现并发 ...
- css文本样式-css学习之旅(4)
color:颜色derction:方向:line-height:行高:letter-spaceing:字符间距:text-align:对齐方向:text-decoration:装饰:text-inde ...
- 【一天一道LeetCode】#56. Merge Intervals
一天一道LeetCode系列 (一)题目 Given a collection of intervals, merge all overlapping intervals. For example, ...
- Cocos2D的平台检查宏
为了避免在非iOS平台包含UIKit.h文件,需要在Prefix.pch文件中添加一个条件判断: #if __CC_PLATFORM_IOS #import <UIKit/UIKit.h> ...
- windows下程序启动检查,只启动一个实例
问题来源:http://bbs.csdn.net/topics/390998279?page=1#post-398983061 // Only_once.cpp : 定义控制台应用程序的入口点. // ...
- 基于GraphCuts图割算法的图像分割----OpenCV代码与实现
转载请注明出处:http://blog.csdn.net/wangyaninglm/article/details/44151213, 来自:shiter编写程序的艺术 1.绪论 图切割算法是组合图论 ...
- mysql导入导出.sql数据
导入sql的命令:source "路径名"+/mytest_emp_dept.sql 常用source 命令 进入mysql数据库控制台, 如mysql -u root -p my ...
- centOS 安装(光安装 和 u盘安装)
光盘安装用这个: http://www.williamlong.info/archives/1912.html 是否保留win7,要作好相关配置.有些插件可以不装. 网络设置:不好弄 如果用u盘安装, ...