LeetCode3——Longest Substring Without Repeating Characters
来源:互联网 发布:电脑测温软件 编辑:程序博客网 时间:2024/05/18 02:37
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) {
int max = 0;
int flag[256];
memset(flag, 0, 256*sizeof(int));
int i = 0;
int len = 0;
while (i < s.size()) {
int k = i;
while (flag[s[k]] == 0) {
len++;
flag[s[k]] = len;
k++;
if (k >= s.size()) goto OK;
}
{
if (max < len) {
max = len;
}
i = i + flag[s[i]];
len = 0;
memset(flag, 0, 256*sizeof(int));
}
}
OK:
if (max < len) max = len;
return max;
}
};
- LeetCode3—Longest Substring Without Repeating Characters
- LeetCode3——Longest Substring Without Repeating Characters
- Leetcode3——Longest Substring Without Repeating Characters
- LeetCode3:Longest Substring Without Repeating Characters
- [LeetCode3] Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters leetcode3
- LeetCode3 Longest Substring Without Repeating Characters
- LeetCode3:Longest Substring Without Repeating Characters
- leetcode3 longest Substring Without Repeating Characters
- LeetCode3:Longest Substring Without Repeating Characters
- Leetcode3 Longest Substring Without Repeating Characters
- leetcode3--Longest Substring Without Repeating Characters
- leetcode3. Longest Substring Without Repeating Characters
- LeetCode3:Longest Substring Without Repeating Characters
- Leetcode3:Longest Substring Without Repeating Characters
- [leetcode3] Longest Substring Without Repeating Characters
- Leetcode3 : Longest Substring Without Repeating Characters
- LeetCode3. Longest Substring Without Repeating Characters
- 从K近邻算法、距离度量谈到KD树、SIFT+BBF算法
- ReactiveCocoa指南一:信号
- C++Primer第五版 第1章 开始(练习解答)
- POJ - 2421 Constructing Roads(最小生成树简单题)
- HDOJ 2639 Bone Collector II(01||第K大背包)
- LeetCode3——Longest Substring Without Repeating Characters
- overlapped 结构
- POJ 2752 Seek the Name, Seek the Fame
- 领域驱动设计的优点
- RCNN & SPP-net & Fast-RCNN & Faster-RCNN
- COCI2014 COCI
- spring mvc配置完后实现下载功能
- LeetCode 3 最大不重复子串
- MVC,MVP,MVVM框架剖析