[LeetCode_3] Longest Substring Without Repeating Characters
LeetCode: 3. Longest Substring Without Repeating Characters
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int ans = 0, i = 0, j = 0;
map <char , char> m;
int n = s.size();
while (i < n && j < n){
// 左闭右开
if(m.find(s[j]) == m.end()){
// 如果j符合
m[s[j]] = s[j];
j +=1;
ans = ans > (j - i ) ? ans :(j - i);
}
else {
// 否则窗口缩小,j不前进
m.erase(s[i]);// 从哈希表中移除
i +=1;
}
}
return ans;
}
};
[LeetCode_3] Longest Substring Without Repeating Characters的更多相关文章
- Leetcode_3. Find the longest substring without repeating characters
3. Find the longest substring without repeating characters Given a string, find the length of the lo ...
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 3. Longest Substring Without Repeating Characters(c++) 15ms
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 【leetcode】Longest Substring Without Repeating Characters
题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...
- Longest Substring Without Repeating Characters(C语言实现)
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- leetcode: longest substring without repeating characters
July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...
- Longest Substring Without Repeating Characters (c#)
Given a string, find the length of the longest substring without repeating characters. For example, ...
随机推荐
- sublime sublimeCodeIntel插件 配置
安装完成后, 弹出一个说明 页面, 不用 管 .可到了这里就是没有提示信息, 忽略 配置sublimeCodeIntel的config文件,告诉他我们需要javascript的提示. 法一: 通过su ...
- h5的离线缓存机制
什么是Manifest: 其实Manifest是一个简单的 文本文件,它的扩展名是任意的,定义需要缓存的文件.资源,当第一次打开时,浏览器会自动缓存相应的资源. Manifest 的特点: 离线浏览: ...
- SqList *L 和 SqList * &L的区别/学习数据结构突然发现不太懂 小祥我查找总结了一下
小祥在学习李春葆的数据结构教程时发现一个小问题,建立顺序表和输出线性表,这两个函数的形参是不一样的. 代码在这里↓↓↓ //定义顺序表L的结构体 typedef struct { Elemtype d ...
- 【vue.js权威指南】读书笔记(第一章)
最近在读新书<vue.js权威指南>,一边读,一边把笔记整理下来,方便自己以后温故知新,也希望能把自己的读书心得分享给大家. [第1章:遇见vue.js] vue.js是什么? vue.j ...
- Error:java:Compilation failed: internal java compiler error
在IDEA中编译时出现这个错误:Error:java:Compilation failed: internal java compiler error! Information:Using javac ...
- dede文章内容页增加视频文件
具体方法:1.在优酷上注册个账号.将要上传的视频在优酷上发布.2.待审核完成后分享复制html代码. 3.在后台发布文章时点击源码,将优酷中复制的代码考过来.4.发布后生成页面即可.(可参照vide ...
- Python开发【十二章】:ORM sqlalchemy
一.对象映射关系(ORM) orm英文全称object relational mapping,就是对象映射关系程序,简单来说我们类似python这种面向对象的程序来说一切皆对象,但是我们使用的数据库却 ...
- ASP.NET TextBox 当鼠标点击后清空默认提示文字[转]
前台文本框里添加下面2个事件属性: OnFocus="javascript:if(this.value=='提示文字') {this.value=''}" OnBlur=" ...
- Html5三维全景
先看DEMO:http://think.weiyingjia.cn/liuming/quanjing/out.html 准备: 1.一张或多张全景图片素材 2.pano2VR软件,链接:http ...
- Hessian怎样实现远程调用
1.Spring中除了提供HTTP调用器方式的远程调用,还对第三方的远程调用实现提供了支持,其中提供了对Hessian的支持. Hessian是由Caocho公司发布的一个轻量级的二进制协议远程调用实 ...