My easy java solution


  • 0
    G

    class Solution {
    public int lengthOfLongestSubstring(String s) {
    if(s == null || s.isEmpty() ){
    return 0;
    }
    int size = s.length();
    int maxLength = 0;
    for(int i =0; i < size; i++){
    HashSet<Character> set = new HashSet<>();
    for(int j = i; j < size; j++){
    char ch = s.charAt(j);
    if(!set.contains(ch)){
    set.add(ch);
    }else{
    break;
    }
    }
    maxLength = Math.max(set.size(), maxLength);

        }
        return maxLength;
    }
    

    }


Log in to reply
 

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