创建 test.java
parent
e87aebda39
commit
486c2e2ebf
|
|
@ -0,0 +1,47 @@
|
|||
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,));
|
||||
|
||||
}
|
||||
|
||||
public static int lengthOfLongestSubstring(String s) {
|
||||
StringBuilder longestString = new StringBuilder();
|
||||
StringBuilder lastMaxString = new StringBuilder();
|
||||
if (s != null){
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char temp = s.charAt(i);
|
||||
if (i == 0){
|
||||
continue;
|
||||
}
|
||||
Character prChar = s.charAt(i-1);
|
||||
if (prChar != temp){
|
||||
boolean in = isInString(temp,longestString);
|
||||
if (!in){
|
||||
lastMaxString.append(temp);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return longestString.length();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static boolean isInString(Character a,StringBuilder b){
|
||||
if (b != null) {
|
||||
for (int i = 0; i < b.length(); i++) {
|
||||
Character temp = b.charAt(i);
|
||||
if (temp == a) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue