Math Problem(Beat 83%)


  • 0
    L

    public class Promoted {

    public String originalDigits(String s) {
    	
    	int[] array=new int[26];
    	for(int i=0;i<s.length();i++)
    		array[s.charAt(i)-'a']++;
    	int[] answer=new int[10];
    	int number0=array[25];
    	int number2=array[22];
    	int number4=array[20];
    	int number6=array[23];
    	int number8=array[6];
    	int number5=array[5]-array[20];
    	int number7=array[18]-array[23];
    	int number1=array[14]-(array[25]+array[22]+array[20]);
    	int number3=array[19]-(array[22]+array[6]);
    	int number9=array[8]-(number5+number6+number8);
    	answer[0]=number0;
    	answer[1]=number1;
    	answer[2]=number2;
    	answer[3]=number3;
    	answer[4]=number4;
    	answer[5]=number5;
    	answer[6]=number6;
    	answer[7]=number7;
    	answer[8]=number8;
    	answer[9]=number9;
    	StringBuilder str=new StringBuilder();
    	for(int i=0;i<answer.length;i++)
    	{
    		int time=answer[i];
    		while(time>0)
    		{
    			str.append(i);
    			time--;
    		}
    		
    		
    	}
    	
    	return str.toString();
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.