题解 | 字符个数统计

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        char[] c = s.toCharArray();
        HashSet<Character> hs = new HashSet<>();
        for(int i =0;i<s.length();i++){
            hs.add(c[i]);
        }
        System.out.print(hs.size());
    }
}

用hashset来进行去重操作,最后再输出hashset的大小就是答案。#牛客春招刷题训练营#https://www.nowcoder.com/discuss/730463403411525632

#牛客春招刷题训练营#
全部评论
点赞 回复 分享
发布于 03-15 16:41 广东

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务