03_Longest Substring Without Repeating Characters
1.Question

2.Solution
public static int lengthOfLongestSubstring(String s) { int max = 0; int len = s.length(); int i = 0 , j = 1; while(i < len && j <= len){ Set item = new HashSet<Character>(); String temp = s.substring(i,j++); for(int k = 0; k < temp.length(); k++){ if(!item.contains(temp.charAt(k))){ item.add(temp.charAt(k)); max = max > item.size()? max:item.size(); }else{ break; } } if(j > len){ i ++; j = i; } } return max; }
3.Test

    http://www.cnblogs.com/makexu/

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号