Leetcode 009 - Palindrome Number
9.Palindrome Number
https://leetcode.com/problems/palindrome-number/
Description
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
1 | Input: 121 |
Example 2:
1 | Input: -121 |
Example 3:
1 | Input: 10 |
Follow up:
Coud you solve it without converting the integer to a string?
Solution
1 | class Solution(object): |
125. Valid Palindrome
https://leetcode.com/problems/valid-palindrome/
Description
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Note: For the purpose of this problem, we define empty string as valid palindrome.
Example 1:
1 | Input: "A man, a plan, a canal: Panama" |
Example 2:
1 | Input: "race a car" |
Constraints:
sconsists only of printable ASCII characters.
Solution
1 | class Solution: |
不用s == s[::-1]的代码:
1 | class Solution(object): |
131. Palindrome Partitioning
https://leetcode.com/problems/palindrome-partitioning/
Description
Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
Example:
1 | Input: "aab" |
Solution
1 |
|
132. Palindrome Partitioning II[H]
https://leetcode.com/problems/palindrome-partitioning-ii/
Description
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.
Example:
1 | Input: "aab" |
Solution
1 | class Solution: |
234. Palindrome Linked List
https://leetcode.com/problems/palindrome-linked-list/
Description
Given a singly linked list, determine if it is a palindrome.
Example 1:
1 | Input: 1->2 |
Example 2:
1 | Input: 1->2->2->1 |
Follow up:
Could you do it in O(n) time and O(1) space?
Solution
1 | # Definition for singly-linked list. |
336. Palindrome Linked List[H]
https://leetcode.com/problems/palindrome-pairs/
Description
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:
1 | Input: ["abcd","dcba","lls","s","sssll"] |
Example 2:
1 | Input: ["bat","tab","cat"] |
Solution
https://leetcode.com/problems/palindrome-pairs/discuss/79219/Python-solution~
1 | class Solution: |
409. Longest Palindrome
https://leetcode.com/problems/longest-palindrome/
Description
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.
This is case sensitive, for example "Aa" is not considered a palindrome here.
Note:
Assume the length of given string will not exceed 1,010.
Example:
1 | Input: |
Solution
https://leetcode.com/problems/longest-palindrome/solution/
1 | def longestPalindrome(self, s): |
479. Largest Palindrome Product[H]
https://leetcode.com/problems/largest-palindrome-product/
Description
Find the largest palindrome made from the product of two n-digit numbers.
Since the result could be very large, you should return the largest palindrome mod 1337.
Example:
Input: 2
Output: 987
Explanation: 99 x 91 = 9009, 9009 % 1337 = 987
Note:
The range of n is [1,8].
Solution
1 | class Solution: |
680. Valid Palindrome II
https://leetcode.com/problems/valid-palindrome-ii/
Description
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.
Example 1:
1 | Input: "aba" |
Example 2:
1 | Input: "abca" |
Note:
- The string will only contain lowercase characters a-z. The maximum length of the string is 50000.
Solution
https://leetcode.com/problems/valid-palindrome-ii/solution/
https://leetcode.com/problems/valid-palindrome-ii/discuss/701203/Python-Concise-O(n)
1 | class Solution: |





