✅ best JAVA fast solution
JAVA Code\nJAVA []\nclass Solution {\n    public int lengthOfLongestSubstring(String s) {\n        Set<Character>set=new HashSet<>();\n        int maxLength=0;\
# JAVA Code\n``` JAVA []\nclass Solution {\n    public int lengthOfLongestSubstring(String s) {\n        Set<Character>set=new HashSet<>();\n        int maxLength=0;\n        int left=0;\n        for(int right=0;right<s.length();right++){\n           \n            if(!set.contains(s.charAt(right))){\n                set.add(s.charAt(right));\n                maxLength=Math.max(maxLength,right-left+1);\n                \n            }else{\n                while(s.charAt(left)!=s.charAt(right)){\n                    set.remove(s.charAt(left));\n                    left++;\n                }\n                set.remove(s.charAt(left));left++;\n                set.add(s.charAt(right));\n            }\n            \n        }\n        return maxLength;\n    }\n}\n```\n\n### hey friend, why not upvote? \uD83E\uDD72\n\n![upvote_me.jpeg](https://assets.leetcode.com/users/images/53f427bc-92c5-4415-ac63-c3fd542fe70f_1678425517.4273114.jpeg)\n
['Java']