Java 18 ms solution


  • 0
    H
    public class Solution {
        public boolean canConstruct(String ransomNote, String magazine) {
            int [] magInt = new int[26];
            for(int i=0;i<magazine.length();i++){
                magInt[magazine.charAt(i) - 'a']++;
            }
            for(int j=0;j<ransomNote.length();j++){
                if((magInt[ransomNote.charAt(j)-'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.