Beats 96% submissions

  • 0
        public boolean canConstruct(String ran, String mag) {
            char [] r = ran.toCharArray();
            char [] m = mag.toCharArray();
            int []alphabets = new int[26];
            for(char cr:m) alphabets[((int) cr)- ((int)'a')]++;
            for(char cm:r) alphabets[((int) cm)- ((int)'a')]--;
            for(int i: alphabets) {if(i < 0) return false;}
            return true;

Log in to reply

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