Given a string, find the length of the oldest string that does not contain repeating characters.
Example:
Given "abcabcbb" that the oldest string without repeating characters is "abc" , then the length is 3.
Given "bbbbb" , the longest substring is, the "b" length is 1.
Given "pwwkew" that the eldest string is "wke" , the length is 3. Note that the answer must be a substring, "pwke" which is a subsequence and not a substring.
Importjava.util.LinkedList;classSolution { Public intlengthoflongestsubstring (String s) {intnum=0;//record the oldest string length intcurrent=0;//record the current substring length Char[] arr=S.tochararray (); LinkedList<Character> temp=NewLinkedlist<>(); for(intI=0;i<arr.length; i++ ) { if(!temp.contains (Arr[i])) {Temp.add (arr[i]); Current=temp.size (); if(current>num) num=Current ; } Else//if the new character is duplicated with the character in the atomic string, delete the repeated word indicators the character in the string before it, and the new substring is made up of the newly added characters .{temp.add (arr[i]); intfirst=Temp.indexof (Arr[i]); for(intJ=0;j<first; j + +) Temp.remove (); Temp.remove (); } } returnnum; }
Results
Leetcode the oldest string without repeating characters Java implementation