level 1
上进的学渣233
楼主
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) {
int len=s.length();
int max=0;
if(len==0)
return 0;
if(len==1)
return 1;
for(int i=0;i<len;i++){
for(int j=i+1;j<len;j++){
if(s.charAt(i)==s.charAt(j))
{ break;}
else if(max<j-i){
max=j-i;
}
}
}
return max;
}
}
2016年10月09日 06点10分
1
public class Solution {
public int lengthOfLongestSubstring(String s) {
int len=s.length();
int max=0;
if(len==0)
return 0;
if(len==1)
return 1;
for(int i=0;i<len;i++){
for(int j=i+1;j<len;j++){
if(s.charAt(i)==s.charAt(j))
{ break;}
else if(max<j-i){
max=j-i;
}
}
}
return max;
}
}