[Leetcode] 3.Longest Substring Without Repeating Characters(unordered_map)

通过把未访问的结点放到unordered_map中来判断是否重复,代码如下:
class Solution {
public:
int lengthOfLongestSubstring(string s) {
if(s == "")
return ;
unordered_map<char,int> hash;
int len = ;
int res = ;
for(int i = ;i < s.length();i ++)
{
if(hash.find(s[i]) != hash.end())
{
i = hash[s[i]];
hash.clear();
len = ;
}
else
{
hash[s[i]] = i;
len ++;
res = max(len, res);
}
}
return res;
}
};
[Leetcode] 3.Longest Substring Without Repeating Characters(unordered_map)的更多相关文章
- 【leetcode】Longest Substring Without Repeating Characters (middle)
Given a string, find the length of the longest substring without repeating characters. For example, ...
- LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)
题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...
- LeetCode #003# Longest Substring Without Repeating Characters(js描述)
索引 思路1:分治策略 思路2:Brute Force - O(n^3) 思路3:动态规划? O(n^2)版,错解之一:420 ms O(n^2)版,错解之二:388 ms O(n)版,思路转变: 1 ...
- 「LeetCode」0002-Longest Substring Without Repeating Characters(C++)
分析 贪心思想.注意更新每次判断的最长不同子串的左区间的时候,它是必须单调增的(有时候会在这里翻车). 代码 关掉流同步能有效提高速度. static const auto io_sync_off = ...
- C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告
Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...
- LeetCode:Longest Substring Without Repeating Characters(最长不重复子串)
题目链接 Given a string, find the length of the longest substring without repeating characters. For exam ...
- LeetCode OJ:Longest Substring Without Repeating Characters(最长无重复字符子串)
Given a string, find the length of the longest substring without repeating characters. For example, ...
- LeetCode第三题—— Longest Substring Without Repeating Characters(最长无重复子字符串)
题目描述 Given a string, find the length of the longest substring without repeating characters. Example ...
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
随机推荐
- 我和Python的Py交易》》》》》》 命名空间的小弟作用域
命名空间的小弟作用域 在这要明确一个观点,在Python中万物皆对象,而变量指向的就是对象. 变量可以是 类名,函数名,储存数据的变量…… 对象可以是 类 ,被封装的一段代码(函数),数据…… 命名 ...
- 常见java异常英语词汇(一)
denied /dɪ'naɪəd/ adj 拒签 v 拒绝
- Hibernate-关系映射
1.为什么用Hibernate框架: java程序数据保存的变化: * 内存存在:java基础中, 数据保存在内存中,只在内存中暂时存在 * 文件保存:有io/流之后,数据可以保存到文件中 * 数据库 ...
- 成都Uber优步司机奖励政策(1月25日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- spring源码-增强容器xml解析-3.1
一.ApplicationContext的xml解析工作是通过ClassPathXmlApplicationContext来实现的,其实看过ClassPathXmlApplicationContext ...
- 图片文件转换成Base64编码实现ajax提交图片
//上传头像图片 function uploadHead(imgPath) { console.log("imgPath = " + imgPath); var image = n ...
- typescript语法
先来讲一讲TypeScript出现的背景 前端javascript的编程思想与后端java面向对象的编程思想有很大的不同,微软公司借鉴了coffeescript语言,继承了很多C#和java的编程思想 ...
- 「题目代码」P1060~P1065(Java)
P1060 谭浩强C语言(第三版)习题7.5 注意行末空格. import java.util.*; import java.io.*; import java.math.*; import java ...
- Vs2015 遇到 CL:fatal error c1510 cannot load language clui.dll
网上说什么点击修复VS,修改VS的,经验证都不好使,直接下载这个库,放在system32/64下面皆可以了
- RF上传图片各种失败坑,使用pywin32来操作windows窗体
这个上传按钮,使用 Choose File,失败不知道为什么... Name:Choose FileSource:Selenium2Library <test library>Argume ...