problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::permutation_in_string::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static bool checkInclusion (const string &s1, string s2)
 

详细描述

在文件 leetcode.h2209 行定义.

成员函数说明

◆ checkInclusion()

bool leetcode::permutation_in_string::Solution::checkInclusion ( const string &  s1,
string  s2 
)
static

在文件 leetcode.cpp5929 行定义.

5929 {
5930 if(s1.length() > s2.length()) {
5931 return false;
5932 }
5933 unordered_map<char, int> um1;
5934 unordered_map<char, int> um2;
5935 for(char ch: s1) {
5936 um1[ch]++;
5937 }
5938 for(int i = 0; i < s1.length(); i++) {
5939 um2[s2[i]]++;
5940 }
5941 if(um2 == um1) {
5942 return true;
5943 }
5944 for(int i = 0; i + s1.length() < s2.length(); i++) {
5945 um2[s2[i]]--;
5946 um2[s2[i + s1.length()]]++;
5947 if(um2[s2[i]] == 0) {
5948 um2.erase(s2[i]);
5949 }
5950 if(um2 == um1) {
5951 return true;
5952 }
5953 }
5954 return false;
5955 }

被这些函数引用 leetcode::permutation_in_string::TEST().


该类的文档由以下文件生成: