We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2f32fda commit cf4c0a3Copy full SHA for cf4c0a3
003.无重复字符的最长子串/Solution1.java
@@ -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