调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
中等
相关标签
相关企业
提示

给你两个字符串 s1 和 s2 ,写一个函数来判断 s2 是否包含 s1 。如果是,返回 true ;否则,返回 false

换句话说,s1 的排列之一是 s2子串

 

示例 1:

输入:s1 = "ab" s2 = "eidbaooo"
输出:true
解释:s2 包含 s1 的排列之一 ("ba").

示例 2:

输入:s1= "ab" s2 = "eidboaoo"
输出:false

 

提示:

  • 1 <= s1.length, s2.length <= 104
  • s1s2 仅包含小写字母
通过次数
318.4K
提交次数
695.2K
通过率
45.8%


相关企业

提示 1
Obviously, brute force will result in TLE. Think of something else.

提示 2
How will you check whether one string is a permutation of another string?

提示 3
One way is to sort the string and then compare. But, Is there a better way?

提示 4
If one string is a permutation of another string then they must have one common metric. What is that?

提示 5
Both strings must have same character frequencies, if one is permutation of another. Which data structure should be used to store frequencies?

提示 6
What about hash table? An array of size 26?


评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
运行和提交代码需要登录
s1 =
"ab"
s2 =
"eidbaooo"
Source