public int lengthOfLongestSubstring1(String s) {
        if(s.length()<=1) return s.length();
        int i=0, max=1;
        int[] map=new int[256];
        
        for(int k=0; k<256; k++) map[k] = -1;
        
    	while(i<s.length()-1)
    	{
    		map[s.charAt(i)] = i;
    		int j=i+1;
    		for(;j<s.length() && (map[s.charAt(j)] < i || map[s.charAt(j)]== j); j++){
    			map[s.charAt(j)] = j;
    		}
    		max=Math.max(max, j-i);
    		if(j==s.length()) return max;
    		i=map[s.charAt(j)] +1;
    	}
    	return max;
    }