字符串的拍列
题目
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string’s permutations is the substring of the second string.
Example 1:
Input:s1 = “ab” s2 = “eidbaooo”
Output:True
Explanation: s2 contains one permutation of s1 (“ba”).
Example 2:
Input:s1= “ab” s2 = “eidboaoo”
Output: False
Note:
The input strings only contain lower case letters.
The length of both given strings is in range [1, 10,000].
解析重点
1.s2的字串是s1的排列。那么,我们可以把查找过程分为两步。第一步,滑动窗口在s2上,步长为s1。第二步,比较滑动窗口字串和s1内容,判断是否是s1的排列。
2.第一步滑动s2好处理。第二步,我们要怎么处理呢,我们只需要统计两个串字母的数量是否相等即可。
java代码
1 | class Solution { |