题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
import java.util.*; public class Main{ public static void main(String[] arg){ Scanner sc=new Scanner(System.in); while(sc.hasNextLine()){ String str=sc.nextLine(); Map<Character, Integer> map = new HashMap<>(); List<Character> list = new ArrayList<>(); for(int i=0;i<str.length();i++){ if(list.contains(str.charAt(i))){ map.put(str.charAt(i),map.get(str.charAt(i))+1); list.add(str.charAt(i)); }else{ map.put(str.charAt(i),1); list.add(str.charAt(i)); } } for(int j = 1;j<=str.length();j++){ if(map.containsValue(j)){ for(Map.Entry<Character, Integer> entry:map.entrySet()){ if(entry.getValue()==j){ while(list.contains(entry.getKey())){ list.remove(entry.getKey()); } } } break; } } for(int j = 0;j<list.size();j++){ System.out.print(list.get(j)); } System.out.println(); } } }