2022/12/24

LeetCode 1967. Number of Strings That Appear as Substrings in Word

問題:顯示文字中蘊含陣列的文字 解法:RegExp JavaScript
/**
 * @param {string[]} patterns
 * @param {string} word
 * @return {number}
 */
var numOfStrings = function (patterns, word) {
    if (patterns.length < 1 || patterns > 100) {
        return;
    }

    let result = 0;
    patterns.forEach(s => {
        if (new RegExp(s + '+').test(word)) {
            result++;
        }
    })

    return result;
};