题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
JAVA 一个字 干!
import java.util.*; public class Main{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ String inputStr =scanner.nextLine(); int min = Integer.MAX_VALUE; Map<Character,Integer> outMap = new HashMap<>(); int keyNum = 1; for(int i =0;i<inputStr.length();i++){ if(outMap.containsKey(inputStr.charAt(i))){ outMap.put(inputStr.charAt(i),outMap.get(inputStr.charAt(i))+1); }else{ outMap.put(inputStr.charAt(i),1); } } //对map遍历找出value最小的所对应的key for(Integer value:outMap.values()){ min = (value < min)?value:min; } //遍历inputStr, for(int i=0;i<inputStr.length();i++){ if(outMap.get(inputStr.charAt(i)) != min){ System.out.print(inputStr.charAt(i)); } } System.out.println(""); } } }