Leetcode #383 Javascript

/**
 * @param {string} ransomNote
 * @param {string} magazine
 * @return {boolean}
 */
var canConstruct = function(ransomNote, magazine) {
    let lenR = ransomNote.length;
    let list = magazine.split('');
    for(let i = 0; i < lenR; ++i) {
        let index = list.indexOf(ransomNote[i]);
        if(index === -1) {
            return false;
        }
        list.splice(index, 1);
    }
    return true;
};
複製代碼
相關文章
相關標籤/搜索