美团点评 2018 春招 数字字符

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true){
            String s = sc.nextLine();
            int[] nums = new int[10];
            for(int i = 0; i < s.length(); i ++){
                nums[s.charAt(i)-'0'] ++;
            }

            int min = Integer.MAX_VALUE;
            int cur = -1;
            for(int i = 1; i < 10; i ++){
                if(min > nums[i]){
                    min = nums[i];
                    cur = i;
                }
            }
            StringBuffer sb = new StringBuffer();
            if(nums[0] < min){
                sb.append(1);
                while(min -- > 0){
                    sb.append(0);
                }
            }
            else {
                while (min -- >= 0){
                    sb.append(cur);
                }
            }

            System.out.println(sb.toString());
        }
    }


}

你可能感兴趣的:(面试)