- longest-palindromic-subsequence Solution 这个是subset 区别这个和subsequence dp 数组的定义是 dp[i][j]=x的定义是,string[i:j]内的最长回文子序列的长度。 二维dp 所以这个题目迭代的时候要从最后开始迭代,j却要从 range(i+1,n)内迭代。 if the length of string is 7, the last index of the string is 6 Then the sequence of (i,j) will be 5,6 4,5 4,6 3,4 -word-break Solution 一维dp数组,返回值是true or false
-word-break-ii Solution 这个用的是回溯 def backtrack(start,track), 选择列表是 word list
-palindrome-number Solution 这是左右指针的问题 不过这个可以用来当判断一个序列是否是 回文串 palindrome 。It ask you if a number is a palindrome number
- palindromic-substrings Solution Given a string s, return the number of palindromic substrings in it. 同样是利用这个dp数组
for i in range(n-1,-1,-1):
for j in range(i+1,n):
dp[i][j]=(s[i]==s[j]) and dp[i+1][j-1]
Input: s = "aaa"
Output: 6
Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".
- longest-palindrome Solution ultilized counter from collections ,最后是用数学的方式在处理的这个问题
- palindrome-partitioning Solution
Output: [["a","a","b"],["aa","b"]]
utilize the dp[i][j] palindrome first then backtracking, for j in range(start,n), determine if dp[start][j] is a palindrome
for i in range(n-1,-1,-1):
for j in range(i+1,n):
dp[i][j] = (s[i] == s[j]) and dp[i + 1][j - 1]
- valid-anagram
- group-anagrams Solution 这个是哈希表的使用