笔试题:字母序最小的序列的第一张卡片上数字

题目描述:

有52张卡片,大小写的a-z,随意抽任意张成一排,去重后,所有可能的结果中,字母序最小的序列的第一张卡片上是哪个字母?

public class Main{
    

    public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
        String str = sc.next();
        System.out.println(helper2(str));
		
	}
    public static String helper2(String str){
		str=str.toLowerCase();
		char[] strs=str.toCharArray();
		//把字符串数组放入TreeSet中,根据set元素不重复的特性去掉重复元素。根据treeSet的有序性排序
		TreeSet<Character> set=new TreeSet<>();
		for(char ch:strs){
			set.add(ch);
		}
		return ""+set.first();
		
	}
}

猜你喜欢

转载自blog.csdn.net/orangefly0214/article/details/88973515