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 ...
随机推荐
- Restframework框架总结及restful规范
1. django rest framework框架的作用? 帮助开发者可以快速开发出遵循restful规范的API 2. django rest framework框架都有哪些组件(10)? -版本 ...
- element 表单的input循环生成,并可单个input失去焦点单个验证并保存; (多个表单实例)
<div class="box_item"> <el-form ref="aList" :model="form" :ru ...
- spring(二)-反射、动态代理
主要是对上一篇文章中涉及到的点做补充,欢迎指正! 1. java反射知识-Spring IOC 依赖注入 Java反射机制主要提供了以下功能: 在运行时判断任意一个对象所属的类:在运行时构造任意一个 ...
- ECMAScript面向对象术语
面向对象术语1.对象ECMA-262 把对象(object)定义为“属性的无序集合,每个属性存放一个原始值.对象或函数”.严格来说,这意味着对象是无特定顺序的值的数组.尽管 ECMAScript 如此 ...
- ABAP术语-Accounting Document
Accounting Document 原文:http://www.cnblogs.com/qiangsheng/archive/2007/12/12/991731.html Accounting d ...
- Spirng+SpringMVC+Mybatis(一)
实习之后都是在别人搭配好环境的情况下进行一些业务的编写,脑袋已经不记得如何搭建一个ssm项目的,所以周末有空补了一下. 首先新建一个test数据库,并且在里面插入三条数据.如图下 编写一个User B ...
- filter-policy和AS-PATH-FILTER过滤BGP路由条目
Filter-policy过滤BGP路由条目 一:根据项目需求搭建好拓扑图如下: 二:配置 1:对项目图做理论分析,首先RT1和RT2属于EBGP(不同自治系统之间的直连路由),而RT2和RT3属于I ...
- ajax提交时 富文本CKEDITOR 获取不到内容
ckeditor数据向content(页面用以替换的编辑框)的同步 问题: 我们发现,在数据通过ajaxSubmit提交的过程中,并不能将最新的数据进行提交.换句话说,最新的数据无法被jQuery.f ...
- springboot学习(2)
WebMvcConfigurerAdapter 在springboot2.0及以上版本过时问题 WebMvcConfigurerAdapter已经过时,替代方案: 1 实现 WebMvcConfigu ...
- pynlpir + pandas 文本分析
pynlpir是中科院发布的一个分词系统,pandas(Python Data Analysis Library) 是python中一个常用的用来进行数据分析和统计的库,利用这两个库能够对中文文本数据 ...