I dont understand why its not working


  • 0
    V

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

    HashMap<Character,Integer>  map = new HashMap<Character,Integer>();
    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.containsKey(s.charAt(i)))
         {   
            
         }
         else {
             count = i-(map.get(s.charAt(i)));
             
             if(count>max) max = count;
             count = 1;
             map.clear();
        }
         map.put(s.charAt(i),i);
     }
     return max;
    

    }
    }


Log in to reply
 

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