通过把未访问的结点放到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)的更多相关文章

  1. 【leetcode】Longest Substring Without Repeating Characters (middle)

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  2. LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)

    题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...

  3. 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 ...

  4. 「LeetCode」0002-Longest Substring Without Repeating Characters(C++)

    分析 贪心思想.注意更新每次判断的最长不同子串的左区间的时候,它是必须单调增的(有时候会在这里翻车). 代码 关掉流同步能有效提高速度. static const auto io_sync_off = ...

  5. C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告

    Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...

  6. LeetCode:Longest Substring Without Repeating Characters(最长不重复子串)

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

  7. LeetCode OJ:Longest Substring Without Repeating Characters(最长无重复字符子串)

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  8. LeetCode第三题—— Longest Substring Without Repeating Characters(最长无重复子字符串)

    题目描述 Given a string, find the length of the longest substring without repeating characters. Example ...

  9. LeetCode[3] Longest Substring Without Repeating Characters

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

随机推荐

  1. 北京Uber优步司机奖励政策(3月20日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  2. ASCII、Unicode、UTF-8编码关系

    由于计算机是美国人发明的,因此,最早只有127个字符被编码到计算机里,也就是大小写英文字母.数字和一些符号,这个编码表被称为ASCII编码,比如大写字母A的编码是65,小写字母z的编码是122.但是要 ...

  3. .net core mvc 模型绑定 之 json and urlencoded

    .net core mvc 模型绑定, FromQuery,对应 url 中的 urlencoded string ("?key1=value1&key2=value2") ...

  4. jdbc 连接各种数据库

    package com.fh.controller.ruitai.util; import java.sql.Connection; import java.sql.DriverManager; im ...

  5. 「暑期训练」「基础DP」免费馅饼(HDU-1176)

    题意与分析 中文题就不讲题意了.我是真的菜,菜出声. 不妨思考一下,限制了我们决策的有哪些因素?一,所在的位置:二,所在的时间.还有吗?没有了,所以设dp[i][j]" role=" ...

  6. Jenkins构建完成后实现自动将war包部署到指定服务器

    首先我们需要确定我们的jenkins安装了:publish over ssh 插件,如果没有安装,到-->jenkins首页-->系统管理-->插件管理-->可选安装里面去搜 ...

  7. word record 4

    word record 4 pledge p le g vt. 保证,许诺 snowflake falke->n. 小薄片:火花 deputy de piu ti n. 代理人,代表 etch ...

  8. laravel 的DB::raw() 语法使用

    z之前在项目中遇到一个问题,复杂的sql查询,用laravel的查询构造器,非常的不方便,各种查询条件拼接一长串拼得脑瓜疼:然后想使用原生的sql语句来查询,然后又使用不了laravel的pagina ...

  9. 流畅的python(笔记)

    流畅的python中有很多奇技淫巧,整本书都在强调如何最大限度地利用Python 标准库.介绍了很多python的不常用的数据类型.操作.库等,对于入门python后想要提升对python的认识应该有 ...

  10. 【WXS数据类型】String

    属性: 名称 值类型 说明 [String].constructor [String] 返回值为“String”,表示类型的结构字符串 [String].length [Number] 返回该字符串的 ...