给定一个字符串,找出不含有重复字符的,最长子串的长度

import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class Demo03 {
	public static void main(String[] args) {
		Stack stack = new Stack();
		LinkedList list1 = new LinkedList();
		LinkedList list2 = new LinkedList();
		Scanner console = new Scanner(System.in);
		String str =console.next();
		for(int i = str.length() - 1 ; i >= 0; i--){
		stack.push(str.charAt(i));
		}
		while(stack.size() > 0){
			char a = stack.pop();
			if(list1.contains(a) == true){
				if(list1.size() > list2.size()){
					list2.clear();
					list2.addAll(list1);
				}
				list1.clear();
			}
			list1.add(a);
		}
		System.out.println(list2);
	}
}

运行结果

bbbb
[b]
abcabcbb
[a, b, c]
pwwkew
[w, k, e]


 

你可能感兴趣的:(数据结构)