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

#include <leetcode.h>

静态 Public 成员函数

static int getMinUniqueCharCnt (const string &s, int len)
 
static int lengthOfLongestSubstringTwoDistinct (const string &s)
 

详细描述

在文件 leetcode.h2803 行定义.

成员函数说明

◆ getMinUniqueCharCnt()

int leetcode::longest_substring_with_at_most_two_distinct_characters::Solution::getMinUniqueCharCnt ( const string &  s,
int  len 
)
static

在文件 leetcode.cpp7716 行定义.

7716 {
7717 unordered_map<char, int> um;
7718 for(int i = 0; i < len; i++) {
7719 um[s[i]]++;
7720 }
7721 size_t ans = um.size();
7722 for(int i = 0, j = len; j < s.length(); i++, j++) {
7723 um[s[i]]--;
7724 um[s[j]]++;
7725 if(um[s[i]] == 0) {
7726 um.erase(s[i]);
7727 }
7728 ans = min(ans, um.size());
7729 }
7730 return ans;
7731 }

被这些函数引用 leetcode::longest_substring_with_at_most_k_distinct_characters::Solution::lengthOfLongestSubstringKDistinct() , 以及 lengthOfLongestSubstringTwoDistinct().

◆ lengthOfLongestSubstringTwoDistinct()

int leetcode::longest_substring_with_at_most_two_distinct_characters::Solution::lengthOfLongestSubstringTwoDistinct ( const string &  s)
static

在文件 leetcode.cpp7733 行定义.

7733 {
7734 int l = 1;
7735 int r = s.length();
7736 while(l < r) {
7737 const int mid = (l + r) / 2 + 1;
7738 const int res = getMinUniqueCharCnt(s, mid);
7739 if(res > 2) {
7740 r = mid - 1;
7741 } else {
7742 l = mid;
7743 }
7744 }
7745 return l;
7746 }

引用了 getMinUniqueCharCnt().

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


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