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

#include <leetcode.h>

静态 Public 成员函数

static int longestCommonSubsequence (string text1, string text2)
 

详细描述

在文件 leetcode.h2507 行定义.

成员函数说明

◆ longestCommonSubsequence()

int leetcode::longest_common_subsequence::Solution::longestCommonSubsequence ( string  text1,
string  text2 
)
static

< dp[i][j] = longest common subsequence of text1 end with i and text2 end with j

在文件 leetcode.cpp6758 行定义.

6758 {
6759 vector dp(text1.length(), vector(text2.length(), 0));
6760 for(int i = 0; i < text1.length(); i++) {
6761 for(int j = 0; j < text2.length(); j++) {
6762 if(text1[i] == text2[j]) {
6763 dp[i][j] = (i - 1 < 0 || j - 1 < 0 ? 0 : dp[i - 1][j - 1]) + 1;
6764 } else {
6765 dp[i][j] = max(i - 1 >= 0 ? dp[i - 1][j] : 0, j - 1 >= 0 ? dp[i][j - 1] : 0);
6766 }
6767 }
6768 }
6769 return dp.back().back();
6770 }

被这些函数引用 leetcode::delete_operation_for_two_strings::Solution::minDistance() , 以及 leetcode::longest_common_subsequence::TEST().


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