2430. Maximum Deletions on a String
You are given a string s consisting of only lowercase English letters. In one operation, you can:
- Delete the entire string s, or
- Delete the first i letters of s if the first i letters of s are equal to the following i letters in s, for any i in the range 1 <= i <= s.length / 2.
For example, if s = “ababc”, then in one operation, you could delete the first two letters of s to get “abc”, since the first two letters of s and the following two letters of s are both equal to “ab”.
Return the maximum number of operations needed to delete all of s.
c++
1 | class Solution { |