当前位置:网站首页>LeetCode 3. 无重复字符的最长子串
LeetCode 3. 无重复字符的最长子串
2022-06-30 02:31:00 【小庄同学】
Hi,大家好,我是小庄。
今天打卡的算法题是 —— 力扣 3. 无重复字符的最长子串
该题是校招+社招中,考查频率排名第二的算法题,考察频率排名第一的是反转链表,详细解法请看公众号中的上一篇文章。
该题将采用「哈希表 + 滑动窗口」实现,话不多说,一起来学习吧~
一、Leetcode题目
1、题目地址
2、具体题目


二、实现代码
1、思路:哈希表 + 滑动窗口
(1)具体代码
/**
* @param {string} s
* @return {number}
*/
// 哈希表 + 滑动窗口
// 时间复杂度: O(n),n为字符串s的长度
// 空间复杂度: O(n), n为map的长度
var lengthOfLongestSubstring = function(s) {
let map = new Map();
let start = 0;
let end = 0;
let max = 0;
while(true) {
if(end >= s.length) {
break;
}
let temp = map.get(s[end]);
//map中还没存在
if(temp === undefined || temp < start) {
max = Math.max(max, end - start + 1);
}else {//map中已经存在了
start = temp + 1;
}
map.set(s[end], end);
end++;
}
return max;
};
(2)运行结果
三、讲解视频
四、补充部分
关注公众号:【深漂程序员小庄】: 内含丰富的学习资源和面试经验(不限前端、java),还有学习交流群可加,并且还有各大厂大佬可一起交流学习,一起进步~添加小庄微信,回复【加群】,可加入互联网技术交流群。
边栏推荐
- Global and Chinese market of Kanban software 2022-2028: Research Report on technology, participants, trends, market size and share
- Shenzhen CPDA Data Analyst Certification in July 2022
- 什么是自签名证书?自签名SSL证书的优缺点?
- Four, forty, fourhundred swatches
- Insert sort directly
- SSL证书格式转化的两种方法
- Bucket sort
- Unity TimeLine 数据绑定
- Openlayers 3 built in interaction
- Steam elements hidden in science and Technology Education
猜你喜欢

How to use SMS to deliver service information to customers? The guide is here!

Openlayers 3 built in interaction

Pytorch学习(二)

Ffmpeg source code

How does payment splitting help B2B bulk commodity transactions?

每周推荐短视频:为什么理论正确但得不到预期结果?

FDA ESG regulation: digital certificate must be used to ensure communication security

PR second training notes

What should academic presentation /ppt do?

Enlightenment from the revocation of Russian digital certificate by mainstream CA: upgrade the SSL certificate of state secret algorithm to help China's network security to be autonomous and controlla
随机推荐
Two methods of SSL certificate format conversion
RAII内存管理
Global and Chinese markets of liquid optical waveguides 2022-2028: Research Report on technology, participants, trends, market size and share
SQL injection -day17
DHU programming exercise
Weekly recommended short video: why is the theory correct but can not get the expected results?
day33
Global and Chinese markets for light cargo conveyors 2022-2028: Research Report on technology, participants, trends, market size and share
SiteLock九个常见问题
Five cheapest wildcard SSL certificate brands
Creating exquisite skills in maker Education
如何使用SMS向客户传递服务信息?指南在这里!
Implementation of Sanzi chess with C language
PEM_ read_ bio_ Privatekey() returns null only in ECB mode - PEM_ read_ bio_ PrivateKey() returns NULL in ECB mode only
Global and Chinese market of ERP software for garment and textile industries 2022-2028: Research Report on technology, participants, trends, market size and share
C language pivot_ Invalid argument error resolution for root
dhu编程练习
Select sort
FDA邮件安全解决方案
Global and Chinese market of relay lens 2022-2028: Research Report on technology, participants, trends, market size and share