1178. Number of Valid Words for Each Puzzle
https://leetcode.com/problems/number-of-valid-words-for-each-puzzle
Description
With respect to a given puzzle
string, a word
is valid if both the following conditions are satisfied:
word
contains the first letter ofpuzzle
.For each letter in
word
, that letter is inpuzzle
.For example, if the puzzle is
"abcdefg"
, then valid words are"faced"
,"cabbage"
, and"baggage"
, whileinvalid words are
"beefed"
(does not include'a'
) and"based"
(includes's'
which is not in the puzzle).
Return an array answer
, where answer[i]
is the number of words in the given word list words
that is valid with respect to the puzzle puzzles[i]
. Example 1:
Example 2:
Constraints:
1 <= words.length <= 105
4 <= words[i].length <= 50
1 <= puzzles.length <= 104
puzzles[i].length == 7
words[i]
andpuzzles[i]
consist of lowercase English letters.Each
puzzles[i]
does not contain repeated characters.
ac
Last updated