Permutation in a String
Updated
Problem statement
Given strings pattern and text, return whether a contiguous substring of text is a permutation of pattern. A permutation uses exactly the same characters with the same multiplicities, in any order.
For this exercise, assume the pattern is nonempty and both strings contain only lowercase English letters. Return false when the text is shorter than the pattern.
Function
checkInclusion(pattern: String, text: String) → booleanExamples
Example 1
pattern = "ab"text = "eidbaooo"return = trueThe substring ba has the same two characters as ab.
Example 2
pattern = "ab"text = "eidboaoo"return = falseNo length-2 contiguous substring contains one a and one b.
Constraints
- For this exercise, assume
1 <= pattern.length <= 2000. 0 <= text.length <= 20000.- Both strings use only characters a through z.