#Leetcode# 125. Valid Palindrome
https://leetcode.com/problems/valid-palindrome/
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:
Input: "A man, a plan, a canal: Panama" Output: true
Example 2:
Input: "race a car" Output: false
代码:
class Solution { public: bool isPalindrome(string s) { int len = s.length(); int L = 0, R = len - 1; while(L < R) { if(!isalnum(s[L])) L ++; else if(!isalnum(s[R])) R --; else if((s[L] + 32 - 'a') %32 != (s[R] + 32 - 'a') % 32) return false; else { L ++; R --; } } return true; } };
学到了一个新的函数 $isalnum$ 判断是不是字母或者数字!恰饭去了