Skip to main content

Command Palette

Search for a command to run...

lssr. length

Published
1 min readView as Markdown
class Solution {
    public int lengthOfLongestSubstring(String s) {



        HashSet<Character> st= new HashSet<>();
        int length=0;
        int l=0;
        for(int r=0;r<s.length();r++)
        {
            while(st.contains(s.charAt(r)))
            {
                st.remove(s.charAt(l));
                l++;
            }

            st.add(s.charAt(r));
            length=Math.max(length,r-l+1);
        }
        return length;
    }
}

More from this blog

Amit singh's blog

235 posts