leetcode第三题,JAVA小白求教。。
leetcode吧
全部回复
仅看楼主
level 1
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
level 1
你要问啥?😳
2016年11月25日 16点11分 2
1