[演算法] Harmless Ransom Note:計算陣列中各元素出現的次數
keywords: hash table
, important
計算陣列中各元素出現的次數(calculate the number of elements in an array)
問題描述
這是一個類似單字剪報功能的演算法,告訴它我們希望得到哪些單字(noteText
),然後在一篇文章(magazineText
)中去尋找看看能不能找到這些單字,而且數量要足夠。
因此要寫一個 harmlessRansomNote
function,並且代入兩個參數 noteText
和 magazineText
,如果 noteText 中的單字和數量都能在 magazineText 中被找到,則回傳 true,否則回傳 false。
// return true/false
function harmlessRansomNote (noteText, magazineText) {...}
前置知識
判斷演算法的好壞:Big O Notation & Time Complexity @ PJCHENder HackMD