LeetCode - 3. Longest Substring Without Repeating Characters(388ms)
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)的更多相关文章
- C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告
Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...
- LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)
题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...
- LeetCode 3 Longest Substring Without Repeating Characters 解题报告
LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...
- [LeetCode][Python]Longest Substring Without Repeating Characters
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...
- LeetCode之Longest Substring Without Repeating Characters
[题目描述] Given a string, find the length of the longest substring without repeating characters. Exampl ...
- Leetcode 3. Longest Substring Without Repeating Characters (Medium)
Description Given a string, find the length of the longest substring without repeating characters. E ...
- [Leetcode Week1]Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...
- [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
随机推荐
- Code First 一
Code-First和我们的数据库优先方式是相反的,数据库优先是通过数据库映射出相应的类和上下文,Code-First测试通过创建的类和上下文得到相应的数据库. Code-First主要用于领域驱动设 ...
- jquery mobile 移动web(6)
jquery mobile 针对移动端设备的事件类型. 1.touch 事件. tap 快速触摸屏幕并且离开,类似一种完整的点击操作. taphold 触摸屏幕并保持一段时间. swipe 在1秒内水 ...
- Javascript的加载
最新博客站点:欢迎来访 1. 浏览器加载 (1) 同步加载 在网页中,浏览器加载js文件的方式是通过<script>标签.如下所示: //内嵌脚本 <script type= ...
- Tomcat服务器的介绍、安装配置
[1] Tomcat服务器的介绍 1.是一个免费的.开饭源代码的Servlet服务器,目前非常流行. 2.Tomcat服务器是Apache软件基金会的一个顶级项目,由Apache.Sun等公司共同开发 ...
- round函数在oracle和mysql中用法
1.oracle和mysql通用方法 #round(字段1,小数位数) 四舍五入select round('11.123456',4);结果:11.1235 2.mysql的另外2种保留小数位数方法# ...
- kali2.0 设置输入法 找了好久,亲测有效
kali2.0更新源启用中文输入法 查看版本信(Version): uname -r uname -r 工具(Tools): fcitx fcitx fcitx-table-wbpy 更新源:(Sou ...
- javascript--淘宝页面的放大镜效果
放大镜效果需求: 鼠标放入原图中,会出现一个黄色的遮盖层和一个放大的图片,鼠标移动时候,遮盖层会跟着鼠标一起移动,同时放大的图片会跟着一起移动. 实现过程: 1.鼠标移入,遮盖层和大图片显示 2.鼠标 ...
- hash和history的区别
vue-router 中hash模式和history模式. 在vue的路由配置中有mode选项,最直观的区别就是在url中hash 带了一个很丑的 # ,而history是没有#的.vue默认使用ha ...
- thinkphp发送邮箱(以thinkphp5作为示例)。
第一步:设置我们的邮箱客户端授权码 第二步:下载相应的第三方类库(我这里用的PHPemail) 这是phpemailde 第三方类库的文件下载地址:https://github.com/PHPMail ...
- Solr简单总结
Solr 运行Solr服务 方式一:Jetty服务器启动Solr 进入solr-4.10.2/example目录 打开命令行,执行java –jar start.jar命令,即可启动Solr服务 打开 ...