[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, ...
随机推荐
- JavaScript中一些常用的方法整理
当前时间和输入时间比较 var timeLong = Date.parse(new Date());//当前时间var t1 = Date.parse($("#returnTime2&quo ...
- 延时调用的php代码
比如我们想做一个类似于康盛uchome的定时触发任务,任务靠用户访问触发的,但是你触发任务是不能影响用户本身对页面的访问速度(也就是说不能任务执行十秒钟你就让用户等待十秒钟)刚好昨天把这个弄完了.拿出 ...
- 理解会话Session
- php程序员绝不能违背的安全铁则
作为PHP程序员,特别是新手,对于互联网的险恶总是知道的太少,对于外部的入侵有很多时候是素手无策的,他们根本不知道黑客是如何入侵的.提交入侵.上传漏洞.sql 注入.跨脚本攻击等等.作为最基本的防范你 ...
- 给php添加ssl证书
composer下载时报错: The "https://packagist.org/packages.json" file could not be downloaded: SSL ...
- PPT图片双屏抽奖系统现场主要操作流程介绍
目录 第一步:前期准备工作 第二步:现场预备与辅助展示工作 第三步:现场正式抽取工作 PPT图片双屏抽奖系统-现场抽奖视频实录 第一步:前期准备工作 把第二个步骤优化处理制作好的PPT文件 [图片.p ...
- HDU - 1875 畅通工程再续
Problem Description 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问 ...
- Hybrid技术的设计与实现(转)
浅谈Hybrid技术的设计与实现 前言 随着移动浪潮的兴起,各种APP层出不穷,极速的业务扩展提升了团队对开发效率的要求,这个时候使用IOS&Andriod开发一个APP似乎成本有点过高了,而 ...
- paper 116:自然图像抠图/视频抠像技术梳理(image matting, video matting)
1. Bayesian Matting, Chuang, CVPR 2001.http://grail.cs.washington.edu/projects/digital-matting/paper ...
- Coursera台大机器学习课程笔记7 -- Noise and Error
本章重点: 简单的论证了即使有Noise,机器依然可以学习,VC Dimension对泛化依然起作用:介绍了一些评价Model效果的Error Measurement方法. 一论证即使有Noisy, ...