Longest Substring Without Repeating Characters
来源:互联网 发布:java 四行杨辉三角 编辑:程序博客网 时间:2024/04/29 01:04
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.
public class Solution {
public int lengthOfLongestSubstring(String s) {// Start typing your Java solution below
// DO NOT write main() function
Set<String> candidate = new HashSet<String>();
int length = 0;
for (int k=0; k<s.length();k++) {
for (int i = k; i < s.length(); i++) {
char tmp = s.charAt(i);
if (candidate.contains(String.valueOf(tmp)) ) {
if (length < candidate.size()) {
length = candidate.size();
}
candidate.clear();
}
candidate.add(String.valueOf(tmp));
}
if (length < candidate.size()) {
length = candidate.size();
}
candidate.clear();
}
return length;
}
}
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- cin 清除缓冲区
- iPhone软件开发前需认真考虑问题
- Linux C和MySQL数据库写的一个“电话本管理程序”
- RtlCopyMemoryEx
- 程序员常用字体(vs2008字体修改方案)
- Longest Substring Without Repeating Characters
- linux c Make file 的生成
- Command:
- 自适应网页设计
- Linux logo和屏幕光标
- main 函数输入
- Palindrome. Again Palindrome
- U-boot编译出错-软浮点编译错误
- ARM compilation error, VPF registered