记得这要+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_mapmap类似,都是存储的key-value的值,可以通过key快速索引到value。不同的是unordered_map不会根据key的大小进行排序,存储时是根据keyhash值判断元素是否相同,即unordered_map内部元素是无序的。unordered_mapkey需要定义hash_value函数并且重载operator==

leetcode 3. Longest Substring Without Repeating Characters相关推荐

  1. 【贪心】LeetCode 3. Longest Substring Without Repeating Characters

    LeetCode 3. Longest Substring Without Repeating Characters Solution1:我的答案 该方法中哈希表记录的是字符出现的次数.标准的贪心算法 ...

  2. [LeetCode]3.Longest Substring Without Repeating Characters

    [题目] Given a string, find the length of the longest substring without repeating characters. For exam ...

  3. LeetCode:3. Longest Substring Without Repeating Characters

    https://leetcode.com/problems/longest-substring-without-repeating-characters/description/ 内容描述: Give ...

  4. [LeetCode]--3. Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  5. leetcode 3. Longest Substring Without Repeating Characters 最长非重复子串的长度 滑动窗口法

    题目链接 根据我们之前介绍的滑动窗口法的解法: 滑动窗口法详解 leetcode 438. Find All Anagrams in a String 滑动窗口法 这题,我们不难解决,使用之前的模板. ...

  6. python刷leetcode_零基础python刷leetcode -- 3. Longest Substring Without Repeating Characters

    算法很重要,但是每天也需要学学python,于是就想用python刷leetcode 的算法题,和我一起开始零基础python刷leetcode之旅吧.如有不对的地方,希望指正,万分感谢~~ 题目 最 ...

  7. leetcode 3. Longest Substring Without Repeating Characters | 3. 无重复字符的最长子串(双指针+滑窗)

    题目 https://leetcode.com/problems/longest-substring-without-repeating-characters/ 题解 双指针+滑窗,维护一个 set, ...

  8. LeetCode 3 Longest Substring Without Repeating Characters 区间,想法 难度:1

    https://leetcode.com/problems/longest-substring-without-repeating-characters/ 思路:从某点结束所能取到的最早开头是到目前出 ...

  9. [LeetCode] 3. Longest Substring Without Repeating Characters 题解

    问题描述 输入一个字符串,找到其中最长的不重复子串 例1: 输入:"abcabcbb" 输出:3 解释:最长非重复子串为"abc" 复制代码 例2: 输入:&q ...

最新文章

  1. ant学习笔记之(ant执行命令的详细参数和Ant自带的系统属性)
  2. mac 卸载 eclipse_Mac 新手准备工具集合
  3. 用python做自我介绍_python入门教程NO.2 用python做个自我介绍
  4. mysql 数据库授权(给某个用户授权某个数据库)
  5. 「LG2664 树上游戏」
  6. python中exec是什么意思_Python中的进程分支fork和exec详解
  7. Spring与Struts框架整合
  8. 使用jQuery来实现一个简单的ajax请求
  9. 【java】Thread.Sleep 与 Thread.onSpinWait
  10. 企业需要安全人,看微软对员工的十个安全原则
  11. JAVA数据缓存之内存缓存
  12. Maven —— was cached in the local repository, resolution will not be reattempted until the update ...
  13. 用python制作动态二维码印刷价格_用一行Python代码制作动态二维码
  14. Java循环综合练习四之日历打印
  15. CSS外边距合并和CSS清除浮动
  16. 在线客服系统解决方案:物流行业
  17. 苹果xr怎么截屏_苹果怎么截图?教你各种iPhone机型截屏方法
  18. Debian安装FFmpeg
  19. HNU-计算机系统-讨论课5
  20. 用计算机制作微课教学教案,微课教案设计

热门文章

  1. AMD透露Epyc服务器芯片更多细节 多方面挑战英特尔至强平台
  2. iOS runtime实用篇:让你快速上手一个项目
  3. Java 收集的代码 transient
  4. 【转】WCF OpenTimeout, CloseTimeout, SendTimeout, ReceiveTimeout
  5. ViewStub must have a valid layoutResource
  6. 详解Spring MVC 4之ViewResolver视图解析器
  7. flex4实现图片的动态切换
  8. Windown Server 2003
  9. mysql binlog的查询
  10. CentOS 7 Galera Cluster安装全攻略