125. Valid Palindrome Easy
1/**
2 * [125] Valid Palindrome
3 *
4 * 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.
5 * Given a string s, return true if it is a palindrome, or false otherwise.
6 *
7 * Example 1:
8 *
9 * Input: s = "A man, a plan, a canal: Panama"
10 * Output: true
11 * Explanation: "amanaplanacanalpanama" is a palindrome.
12 *
13 * Example 2:
14 *
15 * Input: s = "race a car"
16 * Output: false
17 * Explanation: "raceacar" is not a palindrome.
18 *
19 * Example 3:
20 *
21 * Input: s = " "
22 * Output: true
23 * Explanation: s is an empty string "" after removing non-alphanumeric characters.
24 * Since an empty string reads the same forward and backward, it is a palindrome.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= s.length <= 2 * 10^5
30 * s consists only of printable ASCII characters.
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/valid-palindrome/
36// discuss: https://leetcode.com/problems/valid-palindrome/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn is_palindrome(s: String) -> bool {
42 false
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_125() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.