题解 | #彩色的砖块#
彩色的砖块
https://www.nowcoder.com/practice/8c29f4d1bea84d6ba2847e079b7420f7
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
String str = in.nextLine();
Set<Character> set = new HashSet<Character>();
for(int i = 0;i<str.length();i++){
set.add(str.charAt(i));
}
if(set.size()==1) System.out.println(1);
else if(set.size()==2) System.out.println(2);
else System.out.println(0);
}
}
使用set元素去重,然后分析set中不重复的元素个数。
CVTE公司福利 672人发布
