leetcode-Longest Substring Without Repeating Characters
2015-11-03 22:43
525 查看
Difficulty:
Medium
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring
is "b", with the length of 1.
Medium
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring
is "b", with the length of 1.
class Solution { public: int lengthOfLongestSubstring(string s) { if(s.empty()) return 0; map<char,int> check; int pre=0; int length=s.length(); int maxLen=INT_MIN; for(int i=0;i<length;++i){ if(check.find(s[i])!=check.end()&&pre<=check[s[i]]) pre=check[s[i]]+1; maxLen=max(maxLen,i-pre+1); check[s[i]]=i; } return maxLen; } };
相关文章推荐
- Mysql调优
- 项目冲刺-第五天
- poj 2385 Apple Catching
- 《探索需求-设计前的质量》阅读笔记一
- IOS多线程
- Hadoop---安装Fuse-DFS(难)
- Eclipse Removing obsolete files from server 问题
- Java Annotation 及几个常用开源项目注解原理简析
- pwnable echo1
- IOS dismissViewControllerAnimated 传值
- hdu4578 Transformation
- 使用SQL语句创建和删除约束
- Java基础(12):关键字static和final
- IOS基础UI之(九) UIPageControl结合UIScrollView实现分页效果
- Python核心编程读笔 1
- Mybatis的整体架构
- 分享一个超棒的动画延迟载入轮播图插件
- SpringMVC+MyBatis数据库连接报错
- tesseract-orc安装
- 深入浅出 JavaScript 中的 this