标签:longest else sts ret int indexof repeat contain public
1 public int lengthOfLongestSubstring(String s) { 2 long length = s.length(); 3 String tmp = ""; 4 int substringLength = 0; 5 for (int i = 0; i < length; i ++) { 6 if (tmp.contains(("" + s.charAt(i)))) { 7 if (tmp.length() > substringLength) 8 substringLength = tmp.length(); 9 int idx = tmp.indexOf(s.charAt(i) + ""); 10 tmp = tmp.substring(idx + 1) + s.charAt(i); 11 } 12 else { 13 tmp = tmp + s.charAt(i); 14 if (substringLength < tmp.length()) 15 substringLength = tmp.length(); 16 } 17 } 18 return substringLength; 19 }
3 Longest Substring Without Repeating Characters
标签:longest else sts ret int indexof repeat contain public
原文地址:http://www.cnblogs.com/cywhyy/p/6246688.html