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].


class Solution {
public boolean checkInclusion(String s1, String s2) {
if (s1 == null || s2 == null || s1.length() > s2.length()) {
return false;
}
int l1 = s1.length();
int l2 = s2.length();
int[] c1 = new int[26];
int[] c2 = new int[26];
for(char c : s1.toCharArray()){
c1[c-'a']++;
}
for(int i=0; i<l2; i++){
if(i>=l1){
c2[s2.charAt(i-l1)-'a']--;
}
c2[s2.charAt(i)-'a']++;
if(Arrays.equals(c1,c2)){
return true;
}
}
return false;
}
}

567. Permutation in String【滑动窗口】的更多相关文章

  1. [LeetCode] 567. Permutation in String 字符串中的全排列

    Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. I ...

  2. 【LeetCode】567. Permutation in String 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/permutati ...

  3. 567. Permutation in String字符串的排列(效率待提高)

    网址:https://leetcode.com/problems/permutation-in-string/ 参考:https://leetcode.com/problems/permutation ...

  4. 567. Permutation in String

    Problem statement: Given two strings s1 and s2, write a function to return true if s2 contains the p ...

  5. 567. Permutation in String判断某字符串中是否存在另一个字符串的Permutation

    [抄题]: Given two strings s1 and s2, write a function to return true if s2 contains the permutation of ...

  6. 7、滑动窗口套路算法框架——Go语言版

    前情提示:Go语言学习者.本文参考https://labuladong.gitee.io/algo,代码自己参考抒写,若有不妥之处,感谢指正 关于golang算法文章,为了便于下载和整理,都已开源放在 ...

  7. [LeetCode] Permutation in String 字符串中的全排列

    Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. I ...

  8. leetcode全部滑动窗口题目总结C++写法(完结)

    3. 无重复字符的最长子串 A: 要找最长的无重复子串,所以用一个map保存出现过的字符,并且维持一个窗口,用le和ri指针标识.ri为当前要遍历的字符,如果ri字符在map中出现过,那么将le字符从 ...

  9. 滑动窗口(Sliding Window)技巧总结

    什么是滑动窗口(Sliding Window) The Sliding Problem contains a sliding window which is a sub – list that run ...

随机推荐

  1. UVA

    A network is composed of N computers connected by N - 1 communication links such that any two comput ...

  2. 第一周复习一 ( HTML表单form)

    form <from id="" name="" method="post/get" action="">& ...

  3. spark复习总结01

    1.MapReduce和spark的对比 MapReduce Spark 数据存储结构:磁盘hdfs文件系统的split 使用内存构建弹性分布式数据集RDD,对数据进行运算和cache 编程范式:Ma ...

  4. Invoke-Obfuscation混淆ps文件绕过Windows_Defender

    前提 powershell只能针对win7之后的系统,之前的win操作系统默认没有安装powershell. 所在目录:C:\Windows\System32\WindowsPowerShell\v1 ...

  5. Javascript中的Date()对象

    创建一个指定的事件对象 需要在构造函数中传递一个表示时间的字符串作为参数例:var d2=new Date("8/27/2019"); 如果直接使用构造函数创建一个Date对象,则 ...

  6. oracle number 类型 只显示10位精度

    ,) show numwidth; 设置为15位 ; xa ------------------ 123456789012.12 或者 TO_CHAR(xa,'FM099999999999.09999 ...

  7. CSP 2019 模板整合

    qwq以下都为9.24后写的模板 namespace IO{ const int S = 1 << 20; char I[S + 1], *Is = I, *It = I, O[S + 1 ...

  8. Java中static关键字的定义

    1.static存在的主要意义 static的主要意义是在于创建独立于具体对象的域变量或者方法.以致于即使没有创建对象,也能使用属性和调用方法! static关键字还有一个比较关键的作用就是 用来形成 ...

  9. 【leetcode】939. Minimum Area Rectangle

    题目如下: Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from t ...

  10. Vue学习笔记【11】——Vue调试工具vue-devtools的安装步骤和使用

    1.fq安装 2.本地安装: Google浏览器 chrome://extensions/ ,打开扩展程序→打开开发者模式→加载已解压的扩展程序,选择解压后的扩展程序包即可.