← Back to problems Solve on LeetCode →

Longest Common Subsequence

LeetCode 1143 • Medium • Dynamic Programming

Return the length of the longest common subsequence of text1 and text2. Example: "ace" vs "abcde"3 ("ace").

TimeO(m×n)
SpaceO(m×n)
dp[i][j]:
Current cell
Result
dp[i][j]
Ready
Press Play. If chars match: extend LCS by 1. Else: take the better of skipping left or top.