We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3a59f00 commit 709049dCopy full SHA for 709049d
C++/longest-palindromic-subsequence.cpp
@@ -4,6 +4,10 @@
4
class Solution {
5
public:
6
int longestPalindromeSubseq(string s) {
7
+ if (s == string(s.rbegin(), s.rend())) { // optional, to optimize special case
8
+ return s.length();
9
+ }
10
+
11
vector<vector<int>> dp(2, vector<int>(s.size(), 1));
12
for (int i = s.length() - 2; i >= 0; --i) {
13
for (int j = i + 1; j < s.length(); ++j) {
0 commit comments