438 Find All Anagrams in a String 找出字符串中所有的变位词
详见:https://leetcode.com/problems/find-all-anagrams-in-a-string/description/
C++:
class Solution {
public:
vector<int> findAnagrams(string s, string p) {
if(s.empty())
{
return {};
}
int ss=s.size(),ps=p.size(),i=0;
vector<int> res,cnt(128,0);
for(char c:p)
{
++cnt[c];
}
for(int i=0;i<ss;++i)
{
bool success=true;
vector<int> tmp=cnt;
for(int j=i;j<i+ps;++j)
{
if(--tmp[s[j]]<0)
{
success=false;
break;
}
}
if(success)
{
res.push_back(i);
}
}
return res;
}
};
参考:https://www.cnblogs.com/grandyang/p/6014408.html
438 Find All Anagrams in a String 找出字符串中所有的变位词的更多相关文章
- [LeetCode] 438. Find All Anagrams in a String 找出字符串中所有的变位词
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...
- 【easy】438.Find All Anagrams in a String 找出字符串中所有的变位词
Input: s: "abab" p: "ab" Output: [0, 1, 2] Explanation: The substring with start ...
- [LeetCode] Find All Anagrams in a String 找出字符串中所有的变位词
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...
- LeetCode 438. Find All Anagrams in a String (在字符串中找到所有的变位词)
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...
- [leetcode]438. Find All Anagrams in a String找出所有变位词
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...
- 剑指Offer 找出字符串中第一个只出现一次的字符
题目描述 找出字符串中第一个只出现一次的字符 如果无此字符 请输出'.' 输入描述: 输入一串字符,由小写字母组成 输出描述: 输出一个字符 输入例子: asdfasdfo 输出例子: o 思路:数组 ...
- 找出字符串中第一个不重复的字符(JavaScript实现)
如题~ 此算法仅供参考,小菜基本不懂高深的算法,只能用最朴实的思想去表达. //找出字符串中第一个不重复的字符 // firstUniqueChar("vdctdvc"); --& ...
- C/C+面试题一:找出字符串中出现最多的字符和次数,时间复杂度小于O(n^2)
已知字符串"aabbbcddddeeffffghijklmnopqrst"编程找出出现最多的字符和次数,要求时间复杂度小于O(n^2) /********************* ...
- js常会问的问题:找出字符串中出现次数最多的字符。
一.循环obj let testStr = 'asdasddsfdsfadsfdghdadsdfdgdasd'; function getMax(str) { let obj = {}; for(le ...
随机推荐
- web.xml文件中各个配置的说明
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://w ...
- wampserver64安装时出现计算机缺少MCVR110.DLL无法安装等
在安装wamp完成后运行出现上述问题,是因为wamp版本与DLL不对称.下面给出 wamp64位下载地址 http://www.onlinedown.net/soft/118187.htm vcred ...
- 扩展HtmlHelper
eg3:扩展HtmlHelper 扩展方法类 1 public static class HtmlExtension 2 { 3 /// ...
- IntelliJ IDEA jrebel6 安装,破解
一.Setting中在线安装JRebel插件,install 二.拷贝下载的jrebel.rar解压后 把里面内容覆盖IDEA插件安装目录中此插件目录之下 下载:http://pan.baidu.co ...
- 定时邮件 已经稳定运行10天+ 从局域网linux到外网邮箱
- HBase使用教程
1 基本介绍 1.1 前言 HBase – Hadoop Database.是一个分布式的.面向列的开源数据库,该技术来源于 Fay Chang 所撰写的Google论文"Bigta ...
- extends && implements
final声明的类不能被继承 方法的重写(@Override): 两同两小一大原则: 方法名相同,参数类型相同 子类返回类型小于等于父类方法返回类型(java里无论怎样都对) 子类抛出异常小于等于 ...
- mysql 转换编码方式
进入mysql 的安装文件夹找到 “ my.ini” 文件 (mysql配置文件) 一.编辑MySql的配置文件 vim /etc/my.cnf 在 [mysqld] 标签下加上三行 default ...
- I.MX6 AW-NB177NF wifi reset
/*********************************************************************** * I.MX6 AW-NB177NF wifi res ...
- SimpliciTI协议栈
SimpliciTI组网过程介绍 1.SimpliciTI支持点对点和星形的网络拓扑结构. 下面介绍以AP为中心的SimpliciTI网路协议的星形拓扑结构通信过程 1)当ED节点上电之后就扫描信 ...