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. 【题解】P1516 青蛙的约会(Exgcd)

    洛谷P1516:https://www.luogu.org/problemnew/show/P1516 思路: 设两只青蛙跳了T步 则A的坐标为X+mT   B的坐标为Y+nT 要使他们相遇 则满足: ...

  2. JS JavaScript实现杨辉三角

    1       1 1      1 2 1    1 3 3 1   1 4 6 4 1 1 5 10 10 5 1 ........ 观察这样的一组数,找出规律,用控制台输出这样规律的数 规律:这 ...

  3. getElementsByName和getElementById

    1: 今天分享工作中遇到的一个小细节 1.1 先介绍一下两个方法分别是: 1.2 getElementById()  :可返回对拥有指定 ID 的第一个对象的引用,如果您需要查找文档中的一个特定的元素 ...

  4. Oracle树形结构数据---常见处理情景

    Oracle树形结构数据---常见处理情景 1.查看表数据结构 SELECT *      FROM QIANCODE.TREE_HIS_TABLE T  ORDER BY T.NODE_LEVEL; ...

  5. 浅谈Java 8的新特性和使用场景

    一.default方法:   通过default方法,可以在接口(Interface interface_name)中添加实例化方法:   代码如下: public interface TestDef ...

  6. Vue--- 使用vuex使用流程 1.0

    Vuex 1.安装vuex npm install  -save vuex 2. 引入 创建store文件夹目录 创建 vuex     指挥公共目录    store['state','action ...

  7. 两台Linux主机 scp免密传输

    两台服务器IP如下配置 Linux1: 10.0.0.1   Linux2: 10.0.0.2 Linux1服务器执行如下操作: #  ssh-keygen -t rsa 然后一直回车就行 # sud ...

  8. Java语言利用Collections.sort对Map,List排序

    1.main方法包含TreeMap排序1,TreeMap排序2,HashMap排序,List<Integer>排序,List<Bean>排序,List<Map>排序 ...

  9. Chrome浏览器调试移动端网页 chrome://inspect/#devices

    我使用的是魅族(魅蓝NOTE6 ),电脑是win 7系统,以下几步就可以轻松使用浏览器内置的功能调试移动端网页了: 注意:谷歌浏览器需要先FQ,不然调试页面会空白或者报404错误,(不会FQ的可以联系 ...

  10. Hive(2)-Hive的安装,使用Mysql替换derby,以及一丢丢基本的HQL

    一. Hive下载 1. Hive官网地址 http://hive.apache.org/ 2. 文档查看地址 https://cwiki.apache.org/confluence/display/ ...