首页 > 其他 > 详细

找出字符串中最长不重复子串

时间:2015-10-19 12:41:58      阅读:327      评论:0      收藏:0      [点我收藏+]
public class AE {
    public static void main(String[] args) {
        //String s = "abacdecfgab";
        String s = "abacdbe";
        System.out.println(noDuplicate(s));
    }

    public static String noDuplicate(String str) {
        String sub = "";
        String result = "";
        for (int i = 0; i < str.length(); i++) {
            String c = "" + str.charAt(i);
            if (sub.contains(c)) {
                if (sub.length() > result.length()) {
                    result = sub;
                }
                sub = sub.substring(sub.indexOf(c)+1);
            }
            sub += c;
        }
        if (sub.length() > result.length()) {
            result = sub;
        }
        return result;
    }
}

 

找出字符串中最长不重复子串

原文:http://www.cnblogs.com/hkzws/p/4891314.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!