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

#include <leetcode.h>

静态 Public 成员函数

static long long maximumSubsequenceCount (string text, string pattern)
 

详细描述

在文件 leetcode.h1809 行定义.

成员函数说明

◆ maximumSubsequenceCount()

long long leetcode::maximize_number_of_subsequences_in_a_string::Solution::maximumSubsequenceCount ( string  text,
string  pattern 
)
static

在文件 leetcode.cpp4701 行定义.

4701 {
4702 long long ans = 0;
4703 long long count = 0;
4704 vector<long long> p1count(text.length());
4705 long long p0count = 0;
4706 long long p1c = 0;
4707 p1count[text.length() - 1] = 0;
4708 for(int i = text.length() - 1; i >= 0; i--) {
4709 if(text[i] == pattern[1]) {
4710 count++;
4711 } else if(text[i] == pattern[0]) {
4712 p0count++;
4713 }
4714 if(i - 1 >= 0) {
4715 p1count[i - 1] = count;
4716 }
4717 }
4718 for(int i = 0; i < text.length(); i++) {
4719 if(text[i] == pattern[0]) {
4720 ans += p1count[i];
4721 }
4722 }
4723 ans += max(p0count, count);
4724 return ans;
4725 }

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


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