当前位置:网站首页>剑指 Offer 48. 最长不含重复字符的子字符串
剑指 Offer 48. 最长不含重复字符的子字符串
2022-06-25 22:09:00 【wen_文文】
请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子字符串的长度。
// 求一个字符串中的最长连续不包含重复字符的字串
var lengthOfLongestSubstring = function (s) {
let len = s.length;
let str = ''; //存放子串
let max = 0; //最长连续不重复字串的长度
for (let i = 0; i < len; i++) {
let char = s.charAt(i);
let index = str.indexOf(char);
if (index === -1) {
// 不含该子串
str += char;
max = str.length > max ? str.length : max;
} else {
// 含有该子符,将子串的起始start向后移动一位,并拼接上新加的字符
str = str.substr(index + 1) + char;
}
}
return max;
};
console.log(lengthOfLongestSubstring('pwwkew')) //3
边栏推荐
- Understanding of pseudo classes
- Px4 simulation basis
- 先序线索二叉树
- 谷歌浏览器(Chrome)最新v80版本下载
- Analyse des cinq causes profondes de l'échec du développement de produits
- unsigned与signed之大白话
- Leetcode-1528- rearrange string - hash table - string
- 支付宝支付接口沙箱环境测试以及整合到一个ssm电商项目中
- Run the dronekit flight control application on Shumei faction under px4-jmavsim software simulation environment
- Qtcreator formatting code
猜你喜欢
随机推荐
Reproduction of an implant found by Kaspersky that writes shellcode into evenlog
Spark日志分析
Uniapp - call payment function: Alipay
c_ uart_ interface_ Example and offboard modes
说说单例模式!
mysql5.7版本在配置文件my.ini[mysqld]加上skip-grant-tables后无法启动
A. Balance the Bits--Codeforces Round #712 (Div. 1)
Binary, hexadecimal, big end and small end
先序线索二叉树
Using Google protobuf protocol environment configuration in PHP
Architecture part -- the use of UMI framework and DVA
今天说说String相关知识点
MySQL InnoDB lock knowledge points
Jenkins 发布PHP项目代码
mysql
Anaconda一文入门笔记
The simplest screen recording to GIF gadget in history, licecap, can be tried if the requirements are not high
C. Yet Another Card Deck-Educational Codeforces Round 107 (Rated for Div. 2)
SVN
Blob