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

Examples:

Given "abcabcbb", the answer is "abc", which the length is 3.

Given "bbbbb", the answer is "b", with the length of 1.

Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.

 class Solution {
public:
int lengthOfLongestSubstring(string s) {
int l = s.length();
map<char, int> m;
int innerL = ;
int maxL = ;
for(int i=; i<l; i++) {
map<char, int>::iterator it = m.find(s[i]);
if(it != m.end()) {
if(maxL < innerL) {
maxL = innerL;
}
i = i - innerL + it->second - ;
innerL = ;
m.erase(m.begin(), m.end());
}
else {
innerL += ;
m[s[i]] = innerL;
}
}
return (innerL < maxL) ? maxL : innerL;
}
};

LeetCode - 3. Longest Substring Without Repeating Characters(388ms)的更多相关文章

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

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

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

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

  3. LeetCode 3 Longest Substring Without Repeating Characters 解题报告

    LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...

  4. [LeetCode][Python]Longest Substring Without Repeating Characters

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...

  5. LeetCode之Longest Substring Without Repeating Characters

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

  6. Leetcode 3. Longest Substring Without Repeating Characters (Medium)

    Description Given a string, find the length of the longest substring without repeating characters. E ...

  7. [Leetcode Week1]Longest Substring Without Repeating Characters

    Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...

  8. [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. Example 1: In ...

  9. LeetCode[3] Longest Substring Without Repeating Characters

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

随机推荐

  1. 【题解】洛谷P2914[USACO08OCT]断电Power Failure

    洛谷P2914:https://www.luogu.org/problemnew/show/P2914 哇 这题目在暑假培训的时候考到 当时用Floyed会T掉 看楼下都是用Dijkstra 难道没有 ...

  2. Oracle数据库对象,同义词、序列、视图、索引

    数据库对象简介 Oracle 数据库对象又称模式对象 数据库对象是逻辑结构的集合,最基本的数据库对象是表 其他数据库对象包括: 同义词是现有对象的一个别名. 简化SQL语句 隐藏对象的名称和所有者 提 ...

  3. generative models

    A generative model G can be seen as taking a random seed h (say, a sample from a multivariate Normal ...

  4. android中的键值对

    hashmap,contentvalue,namevaluepair,jsonobject ArrayList和HashMap的区别:内部元素:ArrayList储存的是单个对象(此对象是可以通过设置 ...

  5. iOS开发 | 自定义不规则label

    其中有一个不太规则的label:   image.png 这个label顶部的两个角是圆角,底部的两个角是直角,底部还有一个小三角. 思路 CAShapeLayer联合UIBezierPath画一个不 ...

  6. 蚯蚓(noip2016,贪心,单调性)

    题目描述 本题中,我们将用符号⌊c⌋ 表示对 c 向下取整,例如:⌊3.0⌋=⌊3.1⌋=⌊3.9⌋=3 . 蛐蛐国最近蚯蚓成灾了!隔壁跳蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手来帮他们消灭 ...

  7. 2018 Wannafly summer camp Day3--Travel

    Travel 描述 题目描述: 魔方国有n座城市,编号为1~n.城市之间通过n-1条无向道路连接,形成一个树形结构. 澜澜打算在魔方国进行mm次旅游,每次游览至少一座城市.为了方便,每次旅游游览的城市 ...

  8. BZOJ3668: [Noi2014]起床困难综合症(贪心 二进制)

    Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 2708  Solved: 1576[Submit][Status][Discuss] Descript ...

  9. yarn的学习之1-架构

    本文翻译自http://hadoop.apache.org/docs/r2.8.0/hadoop-yarn/hadoop-yarn-site/YARN.html 译注:原文说得有些过于简单的,并且有些 ...

  10. Zabbix 3.x中使用Percona Monitoring Plugins监控MySQL

    1.下载安装percona-zabbix-templates-1.1.7-2.noarch.rpm 下载地址:https://www.percona.com/downloads/percona-mon ...