I dont know why it isnt working


  • 0
    V

    public class Solution {
    public int lengthOfLongestSubstring(String s) {

    Set<Character> map = new HashSet<Character>();
    if(s.length()==0) return 0;
    int len = s.length();
    
    int count =0;
    int max = 0;
    
    for(int i=0;i<len;i++)
     {
         if(!map.contains(s.charAt(i)))
         {   
            count = count + 1;
         }
         else {
               if(count>max) max = count;
               count = 1;
             map.clear();
        }
         map.add(s.charAt(i));
     }
     if(count>max) max = count;
     return max;
    

    }
    }


Log in to reply
 

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