1332. Remove Palindromic Subsequences

解题思路:一道字符串的题目,有三种情况:

  • 字符串为空,返回0
  • 字符串为回文串,返回1
  • 其他情况返回2

时间复杂度:O(1) / 空间复杂度:O(1)

class Solution {
public:
    int removePalindromeSub(string s) {
        return 2 - (s == string(s.rbegin(), s.rend())) - s.empty();
    }
};

Published by Dongwei

stay hungry, stay foolish

Leave a comment