[Leetcode]Longest Substring Without Repeating Characters
来源:互联网 发布:sql server msde win7 编辑:程序博客网 时间:2024/06/05 17:10
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: /*algorithm: two pointer */ int lengthOfLongestSubstring(string s) {// "abcabcbb" vector<int>table(256,-1); int b = 0,i = b; int maxLen = 0; while(i < s.size()){ if(table[s[i]] >=0)//repeat { maxLen = max(maxLen,i-b); for(int k=b;k <table[s[i]];k++)table[s[k]]=-1; b = table[s[i]]+1; table[s[i]] = i; }else{ table[s[i]] =i; } ++i; } maxLen = max(maxLen,i-b);//for end of string case return maxLen; }};
0 0
- LeetCode: Longest Substring Without Repeating Characters
- LeetCode Longest Substring Without Repeating Characters
- LeetCode: Longest Substring Without Repeating Characters
- [Leetcode] Longest Substring Without Repeating Characters
- leetcode 23: Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- LeetCode 3 - Longest Substring Without Repeating Characters
- [LeetCode]Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- 【leetcode】 Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [leetcode] Longest Substring Without Repeating Characters
- LeetCode - Longest Substring Without Repeating Characters
- LeetCode 3: Longest Substring Without Repeating Characters
- leetcode-3:Longest Substring Without Repeating Characters
- leetcode之Longest Substring Without Repeating Characters
- Linux<十一> 硬盘与硬件管理
- 拯救我的windows10,安装centos7,导致windows10引导消失
- python random从集合中随机选择元素
- 10、内存管理⾼级
- Android Cursor(游标)
- [Leetcode]Longest Substring Without Repeating Characters
- Read-Books-List
- 7.MVC设计模式
- Linux下文本分析工具awk的简单使用
- Spark修炼之道(进阶篇)——Spark入门到精通:第八节 Spark SQL与DataFrame(一)
- 编写一个写字板初步了解Winform编程(二)——界面设计
- 10,main函数分析
- iOS UI CodeSnippet
- Activity中去除标题栏