当前位置:网站首页>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 markets for wireless security in LTE networks 2022-2028: Research Report on technology, participants, trends, market size and share
- 速看 2021-2022年23项重大网络犯罪统计数据
- [NPM] solve the problem of error reporting when installing typeorm with NPM
- 002 color classification
- 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
- 最小栈详解
- FDA邮件安全解决方案
- Shell Sort
- matlab代码运行教程(如何运行下载的代码)
- FDA mail security solution
猜你喜欢

Digicert、Sectigo、Globalsign代码签名证书的区别

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

FDA mail security solution

Can autojs code be encrypted? Yes, display of autojs encryption skills

Quick sort

VScode如何Debug(调试)进入标准库文件/第三方包源码

SSL证书格式转化的两种方法

什么是证书透明度CT?如何查询CT logs证书日志?

Shell Sort

希尔排序
随机推荐
What is a dangling pointer- What is a dangling pointer?
Can autojs code be encrypted? Yes, display of autojs encryption skills
Large scale DDoS attacks and simulated DDoS tests against VoIP providers
Global and Chinese market of Kanban software 2022-2028: Research Report on technology, participants, trends, market size and share
Jupyter notebook displays a collection of K-line graphs
2022年7月深圳地区CPDA数据分析师认证
新考纲下的PMP考试有多难?全面解析
matlab代码运行教程(如何运行下载的代码)
三层交换机和二层交换机区别是什么
FDA邮件安全解决方案
Pytoch learning (II)
dhu编程练习
dhu编程练习
DHU programming exercise
走进江苏作家诗人胭脂茉莉|世界读书日
What is a self signed certificate? Advantages and disadvantages of self signed SSL certificates?
dhu编程练习
银行的理财产品一般期限是多久?
Global and Chinese market of ERP software for garment and textile industries 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for light cargo conveyors 2022-2028: Research Report on technology, participants, trends, market size and share