Created
December 30, 2019 17:13
-
-
Save Desolve/8e24d2e832ae7d1379d1d485375f890a to your computer and use it in GitHub Desktop.
0383 Ransom Note
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public boolean canConstruct(String ransomNote, String magazine) { | |
int[] table = new int[26]; | |
for (char c : magazine.toCharArray()) ++table[c - 'a']; | |
for (char c : ransomNote.toCharArray()) | |
if (--table[c - 'a'] < 0) return false; | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment