题解 | #删除字符串中出现次数最少的字符#

删除字符串中出现次数最少的字符

http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9

import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()){
            String s = sc.nextLine();
            char[] cc = s.toCharArray();
            int[] count = new int[26];

            for(char c : cc){
                count[c - 'a'] += 1;
            }
            int minValue = Integer.MAX_VALUE;

            for(int i = 0; i < 26; ++i){
                if(count[i] != 0 && minValue > count[i]){
                    minValue = count[i];
                }
            }
            Set<Character> set = new HashSet<>();

            for(int i = 0; i < 26; ++i){
                if(count[i] == minValue){
                    set.add((char)('a' + i));
                }
            }
            for(char c : cc){
                if(!set.contains(c)){
                    System.out.print(c);
                }
            }

            System.out.println();
        }
    }
}
全部评论

相关推荐

争当牛马还争不上
码农索隆:1.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
点赞 评论 收藏
分享
机械打工仔:我来告诉你原因,是因为sobb有在线简历,有些HR为了快会直接先看在线简历,初步感觉不合适就不会找你要详细的了
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务