diff --git a/Leetcode/CPP/LongestRepeatingSubsequence.cpp b/Leetcode/CPP/LongestRepeatingSubsequence.cpp new file mode 100644 index 00000000..74781a00 --- /dev/null +++ b/Leetcode/CPP/LongestRepeatingSubsequence.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; + +int main() +{ + string str; + cin>>str; + int n = str.length(); + vector> dp(n+1, vector(n+1,0)); + + for(int i=1; i<=n; i++) + { + for(int j=1; j<=n; j++) + { + if(i!=j and str[i-1]==str[j-1]) + dp[i][j] = 1+dp[i-1][j-1]; + else + dp[i][j] = max(dp[i-1][j], dp[i][j-1]); + } + } + cout<