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

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

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

import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input;
        while ((input = br.readLine()) != null) {
            char ch[] = input.toCharArray();
            int[] count = new int[ch.length];
            int[] newcount = new int[ch.length];
            int min = 0;
            for (int i = 0; i < ch.length - 1; i++) {
                for (int j = i + 1; j < ch.length; j++) {
                    if (ch[i] == ch[j]) {
                        count[i]++;
                        count[j]++;
                    }
                }
            }
            for (int i = 0; i < count.length; i++) {
                newcount[i] = count[i];
            }
            Arrays.sort(count);
            for (int i = 0; i < ch.length; i++) {
                if (newcount[i] > count[0]) {
                    System.out.print(ch[i]);
                } else {
                    continue;
                }
            }
            System.out.println("");
        }
    }
}

全部评论

相关推荐

扭转乾坤_:现在企业都是学华为,一直通过丢池子里,最后捞
点赞 评论 收藏
分享
totoroyyw:千年老妖😂
投递华为等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务