详见: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 找出字符串中所有的变位词的更多相关文章

  1. [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 ...

  2. 【easy】438.Find All Anagrams in a String 找出字符串中所有的变位词

    Input: s: "abab" p: "ab" Output: [0, 1, 2] Explanation: The substring with start ...

  3. [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 ...

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

  5. [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 ...

  6. 剑指Offer 找出字符串中第一个只出现一次的字符

    题目描述 找出字符串中第一个只出现一次的字符 如果无此字符 请输出'.' 输入描述: 输入一串字符,由小写字母组成 输出描述: 输出一个字符 输入例子: asdfasdfo 输出例子: o 思路:数组 ...

  7. 找出字符串中第一个不重复的字符(JavaScript实现)

    如题~ 此算法仅供参考,小菜基本不懂高深的算法,只能用最朴实的思想去表达. //找出字符串中第一个不重复的字符 // firstUniqueChar("vdctdvc"); --& ...

  8. C/C+面试题一:找出字符串中出现最多的字符和次数,时间复杂度小于O(n^2)

    已知字符串"aabbbcddddeeffffghijklmnopqrst"编程找出出现最多的字符和次数,要求时间复杂度小于O(n^2) /********************* ...

  9. js常会问的问题:找出字符串中出现次数最多的字符。

    一.循环obj let testStr = 'asdasddsfdsfadsfdghdadsdfdgdasd'; function getMax(str) { let obj = {}; for(le ...

随机推荐

  1. Scrum 常见错误实践 之 形式化的站会

    站会作为一个团队最容易实施的敏捷实践,为广大team leader和老板们所喜欢,但大部分程序员却很抵触.其主要原因就是很多时候站会都流于形式,没能帮助团队成员解决问题.改进效率. 一种常见的情况就是 ...

  2. linux下weblogic11g成功安装后,启动报错Getting boot identity from user

    <2015-7-1 下午05时46分33秒 CST> <Info> <Management> <BEA-141107> <Version: Web ...

  3. exadata(ilom) 练习

    Oracle(R) Integrated Lights Out Manager Version 3.0.16.10 r65138 Copyright (c) 2011, Oracle and/or i ...

  4. mysql最新版中文参考手册在线浏览

    MySQL是最流行的开放源码SQL数据库管理系统,具有快速.可靠和易于使用的特点.同时MySQL也是一种关联数据库管理系统,具有很高的响应速度和灵活性.又因为mysql拥有良好的连通性.速度和安全性, ...

  5. IO流-获取指定目录下文件夹和文件对象【File类】

    一.运用File类实现获取指定目录下文件夹和文件对象 1.File类 2.方法: 获取文件绝对路径 :getAbsolutePath 案例: import java.io.File; /** * 获取 ...

  6. shell操作Hbase

    status:查询集群的一些状态 hbase(main):002:0> status1 active master, 0 backup masters, 1 servers, 0 dead, 3 ...

  7. CSS的两个class选择器紧挨在一起

    有一段HTML代码: <a class="glyphicons white no-js cogwheel" href="#" target="_ ...

  8. 自己写的Android端HttpUtil工具类

    package com.sxt.jcjd.util; import java.io.IOException; import java.io.UnsupportedEncodingException; ...

  9. 在Orchard CMS Theme 用代码定义布局Widgets

    因为公司业务需要,经过本人几个月尝试,使用Orchard CMS 开发一个简单的企业门户(地址是http://www.ubof.cn).在刚开始接触Orchard CMS,对于个性化的网页布局不知道怎 ...

  10. Lightoj 1003 - Drunk(拓扑排序)

    One of my friends is always drunk. So, sometimes I get a bit confused whether he is drunk or not. So ...