Skip to content

Instantly share code, notes, and snippets.

@VallarasuS
Created March 11, 2023 13:09
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 VallarasuS/c768abbd460e68db90d349bbe05b5778 to your computer and use it in GitHub Desktop.
Save VallarasuS/c768abbd460e68db90d349bbe05b5778 to your computer and use it in GitHub Desktop.
class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
int[] charCount = new int[26];
for (char c: magazine.toCharArray()) {
charCount[c - 'a']++;
}
for (char c: ransomNote.toCharArray()) {
if(charCount[c - 'a'] == 0) {
return false;
}
charCount[c - 'a']--;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment