public static int lengthOfLongestSubstring(String str){
if (str == null || "".equals(str)){ return 0; } char[] chars = str.toCharArray();
return 0; } public int lengthOfLongestSubstring_(String s) { if(s == null || s.equals("")){ return 0; } char[] arr = s.toCharArray(); int left = 0; int right = 0; int max = 0; boolean visited [] = new boolean[128]; while(right < arr.length ){ if(visited[(int)arr[right]] == false){ visited[(int)arr[right]] = true; right++; }else{ max = Math.max(max,right - left); while (left < right && arr[right] != arr[left]){ visited[(int)arr[left]] = false; left ++; } left++; right++; } } max = Math.max(max,right - left); return max; }
|