🧩 Two Pointers & Strings
1. Valid Palindrome
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Given a string s, return true if it is a palindrome, or false otherwise.
Example 1:
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.Example 2:
Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.Example 3:
Input: s = " "
Output: true
Explanation: s is an empty string "" after removing non-alphanumeric characters.
Since an empty string reads the same forward and backward, it is a palindrome.Constraints:
1 <= s.length <= 2 * 10^5sconsists only of printable ASCII characters.
2. Longest Palindrome
Given a string s, return the longest palindromic substring in s.
Example 1:
Example 2:
Constraints:
1 <= s.length <= 1000sconsist of only digits and English letters (lower-case and/or upper-case).
3. Roman to Integer
Given a string s representing a valid Roman numeral, convert it to an integer.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= s.length <= 15scontains only the characters ('I', 'V', 'X', 'L', 'C', 'D', 'M').It is guaranteed that
sis a valid roman numeral in the range[1, 3999].
4. Backspace String Compare
Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character.
You must implement a solution that runs in O(n) time and uses O(1) extra space.
Example 1:
Example 2:
Last updated