博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
无重复字符的最长子串
阅读量:4105 次
发布时间:2019-05-25

本文共 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/

你可能感兴趣的文章
苏宁产品经理面经
查看>>
百度产品经理群面
查看>>
去哪儿一面+平安科技二面+hr面+贝贝一面+二面产品面经
查看>>
element ui 弹窗在IE11中关闭时闪现问题修复
查看>>
vue 遍历对象并动态绑定在下拉列表中
查看>>
Vue动态生成el-checkbox点击无法选中的解决方法
查看>>
python __future__
查看>>
MySQL Tricks1
查看>>
python 变量作用域问题(经典坑)
查看>>
pytorch
查看>>
pytorch(二)
查看>>
pytorch(三)
查看>>
pytorch(四)
查看>>
pytorch(5)
查看>>
pytorch(6)
查看>>
opencv 指定版本下载
查看>>
ubuntu相关
查看>>
C++ 调用json
查看>>
nano中设置脚本开机自启动
查看>>
动态库调动态库
查看>>