Skip to content

Instantly share code, notes, and snippets.

@munguial
Created May 3, 2020 23:12
Show Gist options
  • Save munguial/ee0185f93280c1e3bc96ced23aeddf38 to your computer and use it in GitHub Desktop.
Save munguial/ee0185f93280c1e3bc96ced23aeddf38 to your computer and use it in GitHub Desktop.
Day 3 - Ransom Note
class Solution {
fun canConstruct(ransomNote: String, magazine: String): Boolean {
var m = HashMap<Char, Int>()
magazine.forEach {
if (m.containsKey(it)) {
m[it] = m[it]!!.plus(1)
} else {
m[it] = 1
}
}
ransomNote.forEach {
if (m.containsKey(it) && m.get(it)!! > 0) {
m[it] = m[it]!!.minus(1)
} else {
return false
}
}
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment