Skip to content

Commit 709049d

Browse files
authored
Update longest-palindromic-subsequence.cpp
1 parent 3a59f00 commit 709049d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

C++/longest-palindromic-subsequence.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
class Solution {
55
public:
66
int longestPalindromeSubseq(string s) {
7+
if (s == string(s.rbegin(), s.rend())) { // optional, to optimize special case
8+
return s.length();
9+
}
10+
711
vector<vector<int>> dp(2, vector<int>(s.size(), 1));
812
for (int i = s.length() - 2; i >= 0; --i) {
913
for (int j = i + 1; j < s.length(); ++j) {

0 commit comments

Comments
 (0)