Wiki
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers. Examples in English include “A man, a plan, a canal, Panama!”, “Amor, Roma”, “race car”, “stack cats”, “step on no pets”, “taco cat”, “put it up”, “Was it a car or a cat I saw?” and “No ‘x’ in Nixon”.
Problems
Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.
Solution


Palindrome Pairs
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome.
Example 1:
Given words = [“bat”, “tab”, “cat”]
Return [[0, 1], [1, 0]]
The palindromes are [“battab”, “tabbat”]Example 2:
Given words = [“abcd”, “dcba”, “lls”, “s”, “sssll”]
Return [[0, 1], [1, 0], [3, 2], [2, 4]]
The palindromes are [“dcbaabcd”, “abcddcba”, “slls”, “llssssll”]
Solution


Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.
For example:
Given “aacecaaa”, return “aaacecaaa”.
Given “abcd”, return “dcbabcd”.
Solution


Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
For example, given s = “aab”,
Return
[
[“aa”,”b”],
[“a”,”a”,”b”]
]
Solution
 Using DP to accelerate the backtracking process.


Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.
Return the minimum cuts needed for a palindrome partitioning of s.
For example, given s = “aab”,
Return 1 since the palindrome partitioning [“aa”,”b”] could be produced using 1 cut.
Solution
 build up the two dimentional matrix while retrieving the result.


Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
“A man, a plan, a canal: Panama” is a palindrome.
“race a car” is not a palindrome.
Solution


Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.
Solution
Just reverse the whole number.
123456789101112class Solution {public:bool isPalindrome(int x) {if(x < 0) return false;long a = 0, t = x;while(t) {a = 10*a + t%10;t /= 10;}return a == x;}};Just reverse half of the number, but we have to exclude some exceptions before.
123456789101112class Solution {public:bool isPalindrome(int x) {if(x<0  (x>0 && x%10==0)) return false;int a = 0;while(a < x) {a = 10*a + x%10;x /= 10;}return a>x? a/10==x : a==x;}};
Palindrome Permutation II
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form.
For example:
Given s = “aabb”, return [“abba”, “baab”].
Given s = “abc”, return [].
Solution


C basics
haracter classification functions
They check whether the character passed as parameter belongs to a certain category:
 isalnum Check if character is alphanumeric (function)
 isalpha Check if character is alphabetic (function)
 isblank Check if character is blank (function)
 iscntrl Check if character is a control character (function)
 isdigit Check if character is decimal digit (function)
 isgraph Check if character has graphical representation (function)
 islower Check if character is lowercase letter (function)
 isprint Check if character is printable (function)
 ispunct Check if character is a punctuation character (function)
 isspace Check if character is a whitespace (function)
 isupper Check if character is uppercase letter (function)
 isxdigit Check if character is hexadecimal digit (function)
Character conversion functions
 tolower Convert uppercase letter to lowercase (function)
 toupper Convert lowercase letter to uppercase (function)
Always welcome new ideas and practical
tricks, just leave them in the comments!