当前位置:网站首页>Leecode question brushing record 1332 delete palindrome subsequence

Leecode question brushing record 1332 delete palindrome subsequence

2022-07-01 04:41:00 Why is there a bug list

List of articles

topic

Give you a string s, It's just made up of letters ‘a’ and ‘b’ form . Every delete operation can be done from s Delete a palindrome in Subsequence .

Returns to delete all characters in a given string ( The string is empty ) The minimum number of deletions .

「 Subsequence 」 Definition : If a string can be obtained by deleting some characters of the original string without changing the order of the original characters , So this string is a subsequence of the original string .

「 Palindrome 」 Definition : If a string is read backward and forward the same , So this string is a palindrome .

Example 1:

Input :s = “ababa”
Output :1
explain : The string itself is a palindrome sequence , Just delete once .
Example 2:

Input :s = “abb”
Output :2
explain :“abb” -> “bb” -> “”.
First delete the palindrome subsequence “a”, And then delete it “bb”.
Example 3:

Input :s = “baabb”
Output :2
explain :“baabb” -> “b” -> “”.
First delete the palindrome subsequence “baab”, And then delete it “b”.

Tips :

1 <= s.length <= 1000
s Just letters ‘a’ and ‘b’

answer

class Solution {
    
  public int removePalindromeSub(String s) {
    
        
         if("".equals(s)) return 0;
        if(new StringBuffer(s).reverse().toString().equals(s))          return 1;
       
        return 2;
    }
   
}
原网站

版权声明
本文为[Why is there a bug list]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202160248184429.html