class Solution {
public int lengthOfLongestSubstring(String s) {
if (s== null || s.length() == 0){
return 0;
}
int max = 0;
int temp = 0;
char c[] = s.toCharArray();
for(int i = 0;i<c.length;i++){
Set<Character> set = new HashSet<Character>();
temp = 0;
for(int j = i;j<c.length;j++){
if(set.contains(c[j])){
break;
}else{
set.add(c[j]);
temp++;
}
}
if (max<temp){
max = temp;
}
}
return max;
}
}
leetcode3-Longest Substring Without Repeating Characters
最新推荐文章于 2024-09-10 10:21:38 发布