当前位置:网站首页>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),还有学习交流群可加,并且还有各大厂大佬可一起交流学习,一起进步~添加小庄微信,回复【加群】,可加入互联网技术交流群。
边栏推荐
- FDA ESG regulation: digital certificate must be used to ensure communication security
- FDA mail security solution
- 主流CA吊销俄罗斯数字证书启示:升级国密算法SSL证书,助力我国网络安全自主可控
- Simple distinction between break and continue
- Unity3D UGUI强制刷新Layout(布局)组件
- 堆排序
- 归并排序
- unity的text首列有标点符号咋办
- Network neuroscience——网络神经科学综述
- IBM WebSphere channel connectivity setup and testing
猜你喜欢

SQL injection -day17

FAQs for code signature and driver signature

什么是自签名证书?自签名SSL证书的优缺点?

最小栈详解

Unity3D UGUI强制刷新Layout(布局)组件

Linear algebra Chapter 4 Summary of knowledge points of linear equations (Jeff's self perception)

Differences among digicert, SECTIONO and globalsign code signing certificates

什么是X.509证书?X.509证书工作原理及应用?

SiteLock九个常见问题

Matlab code running tutorial (how to run the downloaded code)
随机推荐
What is a self signed certificate? Advantages and disadvantages of self signed SSL certificates?
【干货分享】最新WHQL徽标认证申请流程
代码签名、驱动签名的常见问题解答
Quick sort
Heap sort
FDA ESG regulation: digital certificate must be used to ensure communication security
Network neuroscience -- a review of network Neuroscience
什么是证书透明度CT?如何查询CT logs证书日志?
Bucket sort
走进江苏作家诗人胭脂茉莉|世界读书日
What files does a CA digital certificate contain? How to view SSL certificate information?
最小栈详解
Precautions for purchasing wildcard SSL certificate
什么是自签名证书?自签名SSL证书的优缺点?
五个最便宜的通配符SSL证书品牌
Global and Chinese market of wind energy equipment logistics 2022-2028: Research Report on technology, participants, trends, market size and share
Linear algebra Chapter 4 Summary of knowledge points of linear equations (Jeff's self perception)
Insert sort directly
FDA ESG规定:必须使用数字证书保证通信安全
Simple distinction between break and continue