[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入门 (三)
迭代器与生成器 迭代器 迭代是Python最强大的功能之一,是访问集合元素的一种方式. 迭代器是一个可以记住遍历的位置的对象. 迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器 ...
- 8-IdentityServer4登录中心
1-新建webapi IdentityServer4服务器项目 E:\coding\netcore\IdentityServerSample>dotnet new webapi --name ...
- DocX操作word生成报表
1.DocX简介 1.1 简介 DocX是一个在不需要安装word的情况下对word进行操作的开源轻量级.net组件,是由爱尔兰的一个叫Cathal Coffey的博士生开发出来的.DocX使得操作w ...
- 深圳Uber优步司机奖励政策(1月4日~1月10日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- ORB代码框架梳理
这里从单目入手,画了一个框架图:
- apache和IIS共存,服务器对外统一使用80端口
apache和IIS共用80端口为了PHP与ASP各自的执行效率,要在服务器上安装iis与Apache,但是无法同时使用80端口,否则其中必定有一个启动不了.让它们共存的并且访问网站不需要加端口号,解 ...
- RAP2环境搭建整理(超详细)
RAP2是阿里开源的接口管理平台,最近搭建了一下,将部署文档整理如下: 如果途中遇坑会在文章末尾记录下来嘻嘻 首先,确定环境是否部署好. RAP2所需的环境为: node.js 8.9.4+ mysq ...
- List和Turple
List 格式:classmates = ['Michael', 'Bob', 'Tracy'] 读取list长度用:len(classmetes) 索引:索引正向从0开始,逆向从-1开始 在末尾增加 ...
- Linux命令应用大词典-第7章 字符串、文件和命令查找
7.1 grep:字符串.文件和命令的查找 7.2 egrep:在文件或标准输入中查找模式 7.3 fgrep:在每个文件或是标准输入中查找模式 7.4 find:列出文件系统内符合条件的文件 7.5 ...
- Java JDK5.0新特性
JDK5.0新特性 虽然JDK已经到了1.8 但是1.5(5.0)的变化是最大的 1. 增强for循环 foreach语句 foreach简化了迭代器 作用: 对存储对象的容器进行迭代 (数组, co ...