Leetcode_LongestSubstringWithoutRepeatingCharacters
来源:互联网 发布:无法连接所有网络驱动 编辑:程序博客网 时间:2024/06/05 03:46
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.
解题方法.
该题比较简答,可以用两个指针,也可以用简单的动态规划。注意字符串操作即可。
int lengthOfLongestSubstring(string s) { if(s.size() == 0)return 0; int *array = new int[s.size()]; for(int i = 0; i < s.size(); ++i){ array[i] = 0; } int currentmax = 1; array[0] = 1; for(int i = 1; i < s.size(); ++i){ string substr = s.substr(i-array[i-1], array[i-1]); size_t found = substr.find(s[i]); if(found != string::npos){ array[i] = substr.size() - substr.find(s[i]) ; } else{ array[i] = array[i-1] + 1; } if(array[i] > currentmax){ currentmax = array[i]; } } return currentmax; }
0 0
- Leetcode_LongestSubstringWithoutRepeatingCharacters
- Codeforces Round #256 (Div. 2) D. Multiplication Table 二分
- 网站分析使用您的正确分析的重要性
- 了解社交媒体分析过程
- android 邮件开发之javamail
- 数位DP模板
- Leetcode_LongestSubstringWithoutRepeatingCharacters
- Tigase XMPP Server 安装与常见问题
- 2014 Multi-University Training Contest 1
- Android-Async-httpClient 开源代码分析
- vpnc 对独立网段及独立主机的分割隧道(split tunne)建立
- Spring 注解学习(二) 控制层梳理
- 查找oracle数据库表中是否存在系统关键字
- ios除去可变字符串中的某些字符
- 了解Web Analytics(分析)的好处