class Solution {
public int lengthOfLongestSubstring(String s) {
String res = "0";
int max,i,j;
char ch;
max=1;
for(i=0;i<s.length();i++){
ch = s.charAt(i);
for(j=0;j<res.length();j++){
if(res.charAt(j) == s.charAt(i)){
if(res.length()-1 > max){
max = res.length()-1;
}
res = "0";
break;
}
}
res = res + ch;
}
return max;
}
}
LeetCode3 : 无重复字符的最长子串长度
最新推荐文章于 2024-04-06 00:54:12 发布