My Java Solution


  • 0
    R
        public int lengthOfLongestSubstring(String s) {
            int max = 0;
            char[] ar = s.toCharArray();
            for (int i = 0; i < ar.length; i++) {
                Set<Character> set = new LinkedHashSet<>();
                StringBuffer sb = new StringBuffer();
                for (int j = i; j < ar.length; j++) {
                    if (!set.add(ar[j])) {
                        set.clear();
                        break;
                    }
                    sb.append(ar[j]);
                }
                max = Math.max(max, sb.length());
            }
            return max;
        }
    

Log in to reply
 

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