5题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); char [] ch = str.toCharArray(); Map<Character,Integer> mp = new HashMap<>(); for(char c:ch){ mp.put(c,mp.getOrDefault(c,0)+1); } Integer min = Collections.min(mp.values()); for(Character cha:mp.keySet()){ if(mp.get(cha)==min){ str=str.replaceAll(String.valueOf(cha),""); } } System.out.println(str); } }