EASY UNDERSTAND SOLUTION(JAVA,O(n))


  • 0
    M
    public class Solution {
        public boolean canConstruct(String ransomNote, String magazine) {
            int[] ret=new int[26];
            //for(int i=0;i<26;i++)ret[i]=0;
            for(char ch:magazine.toCharArray())ret[ch-'a']++;
            for(char ch:ransomNote.toCharArray()){
                if(--ret[ch-'a']<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.