本文共 680 字,大约阅读时间需要 2 分钟。
public class K { static int clen=0;public static void lengthOfLongestSubstring(String s) {
String tempStrs = "";
for(int i=0;i<s.length();i++){
int lcn= tempStrs.indexOf(s.charAt(i)+""); if(lcn != -1){ if(tempStrs.length() > clen){ clen = tempStrs.length(); } s = s.substring(lcn+1, s.length()); lengthOfLongestSubstring(s); }else{ tempStrs = tempStrs.concat(s.charAt(i)+""); } } System.out.println(clen); System.exit(1); }public static void main(String[] args) {
// TODO Auto-generated method stub String s="abcabcbfdgegfergftttyjtyjktyjtyb"; //String s="cwcwelkiojghgwwqqsdsds"; //String s="cwcpvwelkiojgcgwwqqsdsds"; lengthOfLongestSubstring(s); System.out.println(clen);}
}
转载地址:http://jansi.baihongyu.com/