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

#include <leetcode.h>

静态 Public 成员函数

static string minWindow (string s, const string &t)
 
static bool valid (unordered_map< char, int > &ums, const unordered_map< char, int > &umt)
 

详细描述

在文件 leetcode.h2837 行定义.

成员函数说明

◆ minWindow()

string leetcode::minimum_window_substring::Solution::minWindow ( string  s,
const string &  t 
)
static

在文件 leetcode.cpp7827 行定义.

7827 {
7828 string ans = s;
7829 int l = 0;
7830 int r = 0;
7831 unordered_map<char, int> umt;
7832 unordered_map<char, int> ums;
7833 ums[s[0]]++;
7834 for(char ch: t) {
7835 umt[ch]++;
7836 }
7837 bool flag = true;
7838 while(l <= r && r < s.length() && l < s.length()) {
7839 while(!valid(ums, umt) && r + 1 < s.length()) {
7840 ums[s[++r]]++;
7841 }
7842 while(valid(ums, umt) && l < s.length()) {
7843 flag = false;
7844 if(r - l + 1 < ans.length()) {
7845 ans = s.substr(l, r - l + 1);
7846 }
7847 ums[s[l++]]--;
7848 }
7849 if(flag) {
7850 return "";
7851 }
7852 if(r == s.length() - 1) {
7853 break;
7854 }
7855 }
7856 return ans;
7857 }
static bool valid(unordered_map< char, int > &ums, const unordered_map< char, int > &umt)
Definition: leetcode.cpp:7859

引用了 valid().

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

◆ valid()

bool leetcode::minimum_window_substring::Solution::valid ( unordered_map< char, int > &  ums,
const unordered_map< char, int > &  umt 
)
static

在文件 leetcode.cpp7859 行定义.

7859 {
7860 for(const auto &[k, v]: umt) {
7861 if(!ums.contains(k) || ums[k] < v) {
7862 return false;
7863 }
7864 }
7865 return true;
7866 }

被这些函数引用 minWindow().


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