Skip to content

Commit cf4c0a3

Browse files
committed
无重复字符的最长子串
1 parent 2f32fda commit cf4c0a3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int lengthOfLongestSubstring(String s) {
3+
char[] str=s.toCharArray();
4+
int max=0;
5+
int leftIndex=0;//左指针指向字符串的开始位置
6+
//end代表字符串结束位置
7+
for(int end=0;end<str.length;end++){
8+
for(int i=leftIndex;i<end;i++){
9+
if(str[i]==str[end]){
10+
max=max>(end-leftIndex)?max:end-leftIndex;
11+
leftIndex=i+1;
12+
break;
13+
}
14+
}
15+
}
16+
//到最后可能没有使str[i]==str[end]
17+
return max>(str.length-leftIndex)?max:str.length-leftIndex;
18+
}
19+
}

0 commit comments

Comments
 (0)