Simple Java Solution beats 80%


  • 0
    D

    public class Solution {

        public String originalDigits(String s) {
            if(s==null||s.length()==0) return "";
            int[] count=new int[128];
            for(int i=0;i<s.length();i++){
                count[s.charAt(i)]++;
            }
            int[] nums=new int[10];
            nums[0]=count['z'];
            nums[2]=count['w'];
            nums[4]=count['u'];
            nums[6]=count['x'];
            nums[8]=count['g'];
            nums[1]=count['o']-nums[0]-nums[2]-nums[4];
            nums[3]=count['h']-nums[8];
            nums[5]=count['f']-nums[4];
            nums[7]=count['s']-nums[6];
            nums[9]=count['i']-nums[5]-nums[6]-nums[8];
            StringBuilder sb=new StringBuilder();
            for(int i=0;i<10;i++){
                for(int j=nums[i];j>0;j--) sb.append(i);
            }
            return sb.toString();
        }
    

    }


Log in to reply
 

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