leetcode 3. Longest Substring Without Repeating Characters
记得这要+1,j = std::max(j,container[s[i]]+1);
class Solution { public:int lengthOfLongestSubstring(string s) {int length = s.size();if(length <= 0)return 0;unordered_map<char,int> container;int max_num = 0;for(int i = 0,j = 0;i < length;i++){if(container.find(s[i]) != container.end())j = std::max(j,container[s[i]]+1);container[s[i]] = i;max_num = std::max(max_num,i-j+1);}return max_num;} };
https://www.cnblogs.com/StrayWolf/p/6701197.html?utm_source=itdadao&utm_medium=referral
unordered_map
和map
类似,都是存储的key-value
的值,可以通过key
快速索引到value
。不同的是unordered_map
不会根据key
的大小进行排序,存储时是根据key
的hash
值判断元素是否相同,即unordered_map
内部元素是无序的。unordered_map
的key
需要定义hash_value
函数并且重载operator==
。
leetcode 3. Longest Substring Without Repeating Characters相关推荐
- 【贪心】LeetCode 3. Longest Substring Without Repeating Characters
LeetCode 3. Longest Substring Without Repeating Characters Solution1:我的答案 该方法中哈希表记录的是字符出现的次数.标准的贪心算法 ...
- [LeetCode]3.Longest Substring Without Repeating Characters
[题目] Given a string, find the length of the longest substring without repeating characters. For exam ...
- LeetCode:3. Longest Substring Without Repeating Characters
https://leetcode.com/problems/longest-substring-without-repeating-characters/description/ 内容描述: Give ...
- [LeetCode]--3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- leetcode 3. Longest Substring Without Repeating Characters 最长非重复子串的长度 滑动窗口法
题目链接 根据我们之前介绍的滑动窗口法的解法: 滑动窗口法详解 leetcode 438. Find All Anagrams in a String 滑动窗口法 这题,我们不难解决,使用之前的模板. ...
- python刷leetcode_零基础python刷leetcode -- 3. Longest Substring Without Repeating Characters
算法很重要,但是每天也需要学学python,于是就想用python刷leetcode 的算法题,和我一起开始零基础python刷leetcode之旅吧.如有不对的地方,希望指正,万分感谢~~ 题目 最 ...
- leetcode 3. Longest Substring Without Repeating Characters | 3. 无重复字符的最长子串(双指针+滑窗)
题目 https://leetcode.com/problems/longest-substring-without-repeating-characters/ 题解 双指针+滑窗,维护一个 set, ...
- LeetCode 3 Longest Substring Without Repeating Characters 区间,想法 难度:1
https://leetcode.com/problems/longest-substring-without-repeating-characters/ 思路:从某点结束所能取到的最早开头是到目前出 ...
- [LeetCode] 3. Longest Substring Without Repeating Characters 题解
问题描述 输入一个字符串,找到其中最长的不重复子串 例1: 输入:"abcabcbb" 输出:3 解释:最长非重复子串为"abc" 复制代码 例2: 输入:&q ...
最新文章
- ant学习笔记之(ant执行命令的详细参数和Ant自带的系统属性)
- mac 卸载 eclipse_Mac 新手准备工具集合
- 用python做自我介绍_python入门教程NO.2 用python做个自我介绍
- mysql 数据库授权(给某个用户授权某个数据库)
- 「LG2664 树上游戏」
- python中exec是什么意思_Python中的进程分支fork和exec详解
- Spring与Struts框架整合
- 使用jQuery来实现一个简单的ajax请求
- 【java】Thread.Sleep 与 Thread.onSpinWait
- 企业需要安全人,看微软对员工的十个安全原则
- JAVA数据缓存之内存缓存
- Maven —— was cached in the local repository, resolution will not be reattempted until the update ...
- 用python制作动态二维码印刷价格_用一行Python代码制作动态二维码
- Java循环综合练习四之日历打印
- CSS外边距合并和CSS清除浮动
- 在线客服系统解决方案:物流行业
- 苹果xr怎么截屏_苹果怎么截图?教你各种iPhone机型截屏方法
- Debian安装FFmpeg
- HNU-计算机系统-讨论课5
- 用计算机制作微课教学教案,微课教案设计
热门文章
- AMD透露Epyc服务器芯片更多细节 多方面挑战英特尔至强平台
- iOS runtime实用篇:让你快速上手一个项目
- Java 收集的代码 transient
- 【转】WCF OpenTimeout, CloseTimeout, SendTimeout, ReceiveTimeout
- ViewStub must have a valid layoutResource
- 详解Spring MVC 4之ViewResolver视图解析器
- flex4实现图片的动态切换
- Windown Server 2003
- mysql binlog的查询
- CentOS 7 Galera Cluster安装全攻略