博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
567. Permutation in String【滑动窗口】
阅读量:4363 次
发布时间:2019-06-07

本文共 1139 字,大约阅读时间需要 3 分钟。

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
=l1){ c2[s2.charAt(i-l1)-'a']--; } c2[s2.charAt(i)-'a']++; if(Arrays.equals(c1,c2)){ return true; } } return false; }}

转载于:https://www.cnblogs.com/Roni-i/p/11222403.html

你可能感兴趣的文章
1083 是否存在相等的差
查看>>
Redis总结(四)Redis 的持久化(转载)
查看>>
About_Return
查看>>
10.24给TA的话
查看>>
数组_leetcode209
查看>>
日系插画学习笔记(三):光影与结构
查看>>
C语言——几道习题
查看>>
CentOS——自己安装网卡驱动
查看>>
工具系列 | VScode Remote 远程开发与调试(告别SSH)
查看>>
Django QuestSet API (官方文档)
查看>>
2018 Multi-University Training Contest 10
查看>>
ArcGIS JavaScript API4.8 底图选择的几种方案
查看>>
Linux 后台执行命令
查看>>
多线程学习笔记
查看>>
C# 队列集合的使用
查看>>
POJ 2947 Widget Factory (高斯消元 判多解 无解 和解集 模7情况)
查看>>
PC-LINT
查看>>
Hadoop配置安装手册
查看>>
【agc017E】Jigsaw
查看>>
有关python&&c++的散碎的一些知识点_随时更新
查看>>