/* * 3. Longest Substring Without Repeating Characters * 2016-4-10 by Mingyang * 直接用array代替map,注意遇到重复的替换的是地图里面前一个加1 */ public int lengthOfLongestSubstring(String s) { int len=s.length(); if(s==null||len==0) return 0; int start=0; int[] count=new int[256]; Arrays.fill(count,-1); int max=Integer.MIN_VALUE; for(int i=0;i=start){ start=count[s.charAt(i)]+1; } max=Math.max(max,i-start+1); count[s.charAt(i)]=i; } return max; }