Clean JAVA solution using LinkedList

  • 0
    public class Solution {
        public int lengthOfLongestSubstring(String s) {
            int max=0; 
            LinkedList <Character> seq=new LinkedList <Character> ();
            for(int i=0; i<s.length(); i++){
                char cur_char=s.charAt(i);
                if (seq.indexOf(cur_char)>=0){
                    int num=seq.indexOf(cur_char)+1;
                    while(num-->0) seq.removeFirst();
                if(max<seq.size()) max=seq.size();    
            return max;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.