3.Longest Substring Without Repeating Characters
来源:互联网 发布:网站源码腾讯 编辑:程序博客网 时间:2024/05/09 02:17
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) { unordered_map<char, int> myMap; string::iterator iter = s.begin(); int pre = 0; int next = 0; int index = 0; int maxLength = 0; for (; iter != s.end(); ++iter,index++) { if ( myMap.find(*iter) == myMap.end() ) { next = index; myMap[*iter] = index; if (maxLength < next - pre + 1) maxLength = next - pre + 1; } else { if (myMap[*iter] < pre) { next = index; if (maxLength < next - pre + 1) maxLength = next - pre + 1; myMap[*iter] = index; } else { next = index; if (maxLength < next - pre) maxLength = next - pre; pre = myMap[*iter] + 1; myMap[*iter] = index; } } } return maxLength; }};
0 0
- [LeetCode]3.Longest Substring Without Repeating Characters
- LeetCode 3.Longest Substring Without Repeating Characters
- LeetCode --- 3. Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- [Leetcode] 3. Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- 3. Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- 3. Longest Substring Without Repeating Characters
- [leetcode] 3.Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- [leetcode] 3. Longest Substring Without Repeating Characters
- 3. Longest Substring Without Repeating Characters
- [Leetcode]3. Longest Substring Without Repeating Characters
- leetcode 3. Longest Substring Without Repeating Characters
- 【Leetcode】3. Longest Substring Without Repeating Characters
- 纯CSS3实现彩色缎带效果
- Project Euler:Problem 35 Circular primes
- 谷歌大脑科学家 Caffe缔造者 贾扬清 微信讲座完整版
- MYSQL Error2003错误解决方案
- Play 填坑之旅 1
- 3.Longest Substring Without Repeating Characters
- 微信关注即可使用Wi-Fi是怎样实现的?
- 在Eclipse中导入两个名字相同的工程的方法
- Linux NFS服务器的安装与配置
- 邮件链接
- Android学习 - 使用及实现系统分享接口
- 【绿皮】新GRE填空补充练习题Exercise11
- k60 NANDFLASH控制器(NFC)
- iOS开发之微信支付