tags: Power button Double pointer String
Given a string, verify that it is a palindrome string, consider only the alphabetic and numeric characters, can ignore letter case.
Description: In this problem, we define the empty string as a valid palindromic sequence.
Example 1:
Input: "A man, a plan, a canal: Panama"
Output: true
Example 2:
Input: "race a car"
Output: false
Source: stay button (LeetCode)
Link: https: //leetcode-cn.com/problems/valid-palindrome
network all the copyright collar button. Commercial reprint please contact the authorized official, non-commercial reprint please indicate the source.
ideas:
(1) is determined only numbers and letters, and the letters case-insensitive
(2) arranged to take two pointers to the string head and tail
(3) traversing the head and tail pointers of the string is determined whether the character is equal to
/*
* @lc app=leetcode.cn id=125 lang=cpp
*
* [125] palindromic sequence verification
*/
// @lc code=start
#include<string>
using namespace std;
class Solution {
public:
bool ischarornum(char c){
if (c >= 'a' && c <= 'z')
return true;
if (c >= 'A' && c <= 'Z')
return true;
if (c >= '0' && c <= '9')
return true;
return false;
}
bool isPalindrome(string s) {
if (s.length()<2)
return true;
int left =0,right = s.length() -1;
while (left < right){
if(!ischarornum(s[left]))
{
left++;
}
else if (!ischarornum(s[right]))
{
right--;
}
else if((s[left]+32-'a') % 32 != (s[right]+32-'a') % 32)
{
return false;
}
else{
left++;right--;
}
}
return true;
}
};
// @lc code=end
Thinking Apparently more than a string of characters, including letters and numbers, so we canFirst extractWe want to compare the character Another problem is that the letters are case-sensitive, we m...
First, the subject description:125. Verify palindromic sequence(simple) Given a string, verify that it is a palindrome string, consider only the alphabetic and numeric characters, can ignore letter ca...
topic: Given a string, verify that it is a palindrome string, consider only the alphabetic and numeric characters, can ignore letter case. Description:In this problem, we will empty string is defined ...
topic: Given a string, verify that it is a palindrome string, consider only the alphabetic and numeric characters, can ignore letter case. Description: In this problem, we define the empty string as a...
table of Contents topic solution_1 Reference material topic Given a string, verify that it is a palindrome string, consider only the alphabetic and numeric characters, can ignore letter case. Descript...
Algorithm [125] leetcode palindromic sequence verification https://leetcode.com/problems/valid-palindrome/ 1)problem 2)answer 1, ordinary ideas The numbers and characters extracted, and then if it is ...
Given a string, verify that it is a palindrome string, consider only the alphabetic and numeric characters, can ignore letter case. Description: In this problem, we define the empty string as a valid ...
Given a string, verify that it is a palindrome string, consider only the alphabetic and numeric characters, can ignore letter case. Description: In this problem, we define the empty string as a valid ...
Title and use cases Solution of a (successful, 4ms, soon) start looking from both sides of the string decimal letters, numbers, letters to upper case letters to lower case, testing for equality. if i ...