题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
import java.util.HashSet; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); String str_out = str; char[] chr = str.toCharArray(); int len = 0; for (char index : chr) { if (len < str.replaceAll(String.valueOf(index), "").length()) { len = str.replaceAll(String.valueOf(index), "").length(); } } for (char index : chr) { if (len == str.replaceAll(String.valueOf(index), "").length()) { str_out = str_out.replaceAll(String.valueOf(index), ""); } } System.out.println(str_out); } }