File tree 2 files changed +6
-17
lines changed
solution/1300-1399/1332.Remove Palindromic Subsequences
2 files changed +6
-17
lines changed Original file line number Diff line number Diff line change 39
39
先删除回文子序列 " ; baab" ; ,然后再删除 " ; b" ; 。
40
40
</pre >
41
41
42
- <p ><strong >示例 4:</strong ></p >
43
-
44
- <pre ><strong >输入:</strong >s = " ;" ;
45
- <strong >输出:</strong >0
46
- </pre >
47
-
48
42
<p >  ; </p >
49
43
50
44
<p ><strong >提示:</strong ></p >
51
45
52
- <ul >
53
- <li><code>0 <= s.length <= 1000</code></li>
54
- <li><code>s</code> 仅包含字母 'a' 和 'b'</li>
55
- </ul >
46
+ - ` 1 <= s.length <= 1000 `
47
+ - ` s ` 仅包含字母 ` 'a' ` 和 ` 'b' `
56
48
57
49
## 解法
58
50
59
51
<!-- 这里可写通用的实现逻辑 -->
60
52
61
- - 如果字符串 s 是个空串,直接返回 0。
62
- - 如果字符串 s 本身是个回文串,那么只需要删除 1 次。
63
- - 如果字符串 s 不是个回文串,我们注意到 s 最多只有两种字母 "a", "b",并且删除的是一个子序列,因此可以先删除所有字母 "a" (` "aaa...aaa" ` 是个回文串),再删除所有字母 "b",即可使得字符串变为空。因此需要的删除次数是 2 次。
53
+ - 如果字符串 s 本身是个回文串,那么只需要删除 1 次。
54
+ - 如果字符串 s 不是个回文串,我们注意到 s 最多只有两种字母 "a", "b",并且删除的是一个子序列,因此可以先删除所有字母 "a" (` "aaa...aaa" ` 是个回文串),再删除所有字母 "b",即可使得字符串变为空。因此需要的删除次数是 2 次。
64
55
65
56
<!-- tabs:start -->
66
57
Original file line number Diff line number Diff line change @@ -42,10 +42,8 @@ Remove palindromic subsequence "baab" then "b".
42
42
<p >  ; </p >
43
43
<p ><strong >Constraints:</strong ></p >
44
44
45
- <ul >
46
- <li><code>1 <= s.length <= 1000</code></li>
47
- <li><code>s[i]</code> is either <code>'a'</code> or <code>'b'</code>.</li>
48
- </ul >
45
+ - ` 1 <= s.length <= 1000 `
46
+ - ` s ` is either ` 'a' ` or ` 'b' `
49
47
50
48
## Solutions
51
49
You can’t perform that action at this time.
0 commit comments