Skip to content

Instantly share code, notes, and snippets.

@Desolve
Created December 30, 2019 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Desolve/8e24d2e832ae7d1379d1d485375f890a to your computer and use it in GitHub Desktop.
Save Desolve/8e24d2e832ae7d1379d1d485375f890a to your computer and use it in GitHub Desktop.
0383 Ransom Note
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