Set a current substring: tempstring
Set up an array that keeps the longest and no repeating substring: list
Ideas:
Judging from the first character,
If the current substring does not include the current character, the current substring joins the current character as the new current substring,
If the current substring includes the current character, judging the position of the current character in the current string, divide the string into two strings according to this position, and if the trailing end adds the current character as the new current substring, the length of the substring in the current substring and the list array is determined, and if the current substring is long, the list is emptied. Joins the current substring, or, if it is equal, joins the current substring directly into the list.
The substring in the last list is the longest substring.
public static void Longestnodupsubstring (String string) {
if (null = = String | | string.length () = = 0) {
Return
}
list<string> list = new arraylist<string> ();
String tempstring = "";
for (int i = 0; i < string.length (); i++) {
if (Tempstring.indexof (String.charat (i)) = =-1) {
TempString + = String.charat (i);
} else {
Int J = Tempstring.indexof (String.charat (i));
TempString = tempstring.substring (j + 1) + String.charat (i);
}
if (list.size () = = 0) {
List.add (tempstring);
} else {
if (Tempstring.length () > List.get (0). Length ()) {
List.clear ();
List.add (tempstring);
} else {
if (tempstring.length () = = List.get (0). Length ()) {
List.add (tempstring);
}
}
}
}
for (int i = 0; i < list.size (); i++) {
System.out.println (List.get (i));
}
}
public static void Main (string[] args) {
LongestNodupSubstring1 ("abcabcabc");
}
Finds substrings of the longest and no repeating character in a string