LeetCode - 383(JS, Easy)

진영·2024년 4월 1일
0

LeetCode

목록 보기
1/16

383. Ransom Note

난이도: Easy

문제해설

Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.
Each letter in magazine can only be used once in ransomNote.

해답

/**
 * @param {string} ransomNote
 * @param {string} magazine
 * @return {boolean}
 */
var canConstruct = function(ransomNote, magazine) {
    for(const char of magazine){
        ransomNote = ransomNote.replace(char, "");
    }

    if(ransomNote === '') return true;
    else return false;
};
profile
개발하고 만드는걸 좋아합니다

0개의 댓글

관련 채용 정보