【leetcode】438. Find All Anagrams in a String
作者:互联网
problem
438. Find All Anagrams in a String
solution1:
class Solution { public: vector<int> findAnagrams(string s, string p) { if(s.empty()) return {}; vector<int> res, pv(256, 0); for(auto a:p) pv[a]++; int sn = s.size(); int i = 0; while(i<sn) { vector<int> tmp = pv; bool is = true; for(int j=i; j<i+p.size(); j++) { if(--tmp[s[j]]<0) { is = false; break; } } if(is) res.push_back(i); i++; } return res; } };View Code
参考
1. Leetcode_438. Find All Anagrams in a String;
完
标签:pv,String,Anagrams,int,Find,438,leetcode 来源: https://www.cnblogs.com/happyamyhope/p/10487588.html