Description
Given a string array words and a string s, return the number of strings in words that are a prefix of s.
Examples
Input:
words = ["a","b","c","ab","bc","abc"], s = "abc"Output:
3Explanation:
a, ab, abc are prefixes.
Input:
words = ["hello", "he", "hell", "help", "world"], s = "hello"Output:
3Explanation:
The strings "he", "hell", and "hello" are prefixes of "hello". "help" is not a prefix because it differs at the 4th character, and "world" shares no common prefix.
Input:
words = ["", "x", "xy", "xyz", "ab"], s = "xyz"Output:
4Explanation:
The empty string "" is always a prefix of any string. "x", "xy", and "xyz" are also prefixes of "xyz". "ab" is not a prefix because it doesn't match from the beginning.
Constraints
- •
1 ≤ words.length ≤ 1000