更新 test.java

master
wangsiyuan 2023-09-05 14:39:51 +08:00
parent 2621c262f3
commit f70a0e7c2c
1 changed files with 6 additions and 4 deletions

View File

@ -4,9 +4,8 @@ package solution;
public class test {
public static void main(String[] args) {
String s = "abcabcbb";
Character a = 'a';
// int length = lengthOfLongestSubstring(s);
// System.out.println(isInString(a,));
int length = lengthOfLongestSubstring(s);
System.out.println(length);
}
@ -17,15 +16,18 @@ public class test {
for (int i = 0; i < s.length(); i++) {
char temp = s.charAt(i);
if (i == 0){
longestString.append(temp);
continue;
}
Character prChar = s.charAt(i-1);
if (prChar != temp){
boolean in = isInString(temp,longestString);
if (!in){
lastMaxString.append(temp);
longestString.append(temp);
}
} else {
lastMaxString = longestString;
}
}
return longestString.length();