字符串最长子串大小

public static int lengthOfLongestSubstring(String s) {
        int max = 0, num = 0;
        char[] chs =s.toCharArray();
        List<Character> temp = new ArrayList<>();
        for (int i = 0; i < chs.length; i++) {
            int index = temp.indexOf(chs[i]);
            if (index>=0) {
                num = temp.size()-index;
                temp=temp.subList(index+1,temp.size());
            } else {
                num++;
                
            }
            temp.add(chs[i]);
            max = Math.max(num, max);
        }
        return max;
    }

posted @ 2017-10-26 16:12  守夜之人  阅读(298)  评论(0编辑  收藏  举报