题解 | #字符个数统计#
字符个数统计
http://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
import java.util.BitSet;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
/**
* @ProjectName: leetcode
* @Package: com.company.niuke
* @ClassName: MergeMap
* @Author: Administrator
* @Description: 合并
* @Date: 2022/2/16 21:58
* @Version: 1.0
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String line = scanner.next();
//总共有128个字符。字需要用128位
BitSet bitSet = new BitSet(128);
for (char c : line.toCharArray()) {
//判断字符c是否已出现
if (!bitSet.get(c)) {
//未出现就设置为已出现
bitSet.set(c);
}
}
//统计有多少字符已出现过
System.out.println(bitSet.cardinality());
}
}