面试题12:字符串无重复子串的最大长度
2017-05-14 17:26
323 查看
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.
1 class Solution { 2 public: 3 int lengthOfLongestSubstring(string s) { 4 int* m = new int[256]; 5 for (int i = 0; i < 256; i++) { 6 m[i] = -1; 7 } 8 int res = 0; 9 int start = -1; 10 int n = s.length(); 11 for (int i = 0; i < n; i++) { 12 start = max(start, m[s[i]]); 13 res = max(res, i - start); 14 m[s[i]] = i; 15 } 16 return res; 17 } 18 19 };
相关文章推荐
- 找出字符串中最大子串的长度(要求子串中的字符不重复)
- 面试题5:求字符串中回文子串的最大长度
- 字符串中不重复连续字符子串的长度最大值
- 面试题:最长回文子串(即求对称字符串的最大长度 )
- 面试题整理12 求字符串括号最大深度子串
- 得到一个字符串最大无重复子串长度
- 字符串中最大对称子串的长度(C++软件工程师面试题)
- lc#3求字符串中不包含重复字符的最大长度子串
- 求一个字符串的最长不重复子串的最大长度
- 百度面试题 求字符串中不含重复字符的最长子串长度
- java 获得字符串中最大重复子串长度
- (程序员面试题)字符串处理之寻找最大不重复子串
- 字符串中对称子串的最大长度
- 对称子字符串的最大长度(程序员面试题精选100题)
- 输入一个字符串,要求找出字符串中最大子串的长度
- 找工作知识储备---数组字符串那些经典算法:最大子序列和,最长递增子序列,最长公共子串,最长公共子序列,字符串编辑距离,最长不重复子串,最长回文子串
- 面试题35:寻找一个字符串中最长的重复子串
- 编程珠玑 用后缀数组求字符串的最大重复子串
- 02_对N个长度最长可达到1000的数进行排序、对给定的一个字符串,找出有重复的字符,并给出其位置、输入一系列整数,将其中最大的数挑出,并将剩下的数进行排序
- 获取最大长度存在巅倒字符串的子串