当前位置:网站首页>Validate palindrome string
Validate palindrome string
2022-06-28 15:07:00 【Hua Weiyun】
title: Verify the palindrome string
date: 2022-04-25 14:21:32
categories: LeetCode
tags: Make a little progress every day
subject
difficulty Simple
Given a string , Verify that it is a palindrome string , Consider only alphabetic and numeric characters , The case of letters can be ignored .
explain : In this question , We define an empty string as a valid palindrome string .
Example 1:
Input : “A man, a plan, a canal: Panama”
Output : true
explain :“amanaplanacanalpanama” It's a palindrome stringExample 2:
Input : “race a car”
Output : false
explain :“raceacar” It's not a palindrome string
Tips :1 <= s.length <= 2 * 105
character string s from ASCII Character composition
Code :
class Solution { public boolean isPalindrome(String s) { // Convert all to lowercase first s = s.toLowerCase(); StringBuilder sCopy = new StringBuilder(); for (int i = 0; i < s.length(); i++) { // Self retaining letters and numbers if(Character.isLetterOrDigit(s.charAt(i))) { sCopy.append(s.charAt(i)); } } // Reverse string StringBuffer sCopy2 = new StringBuffer(sCopy).reverse(); // Compare return sCopy.toString().equals(sCopy2.toString()); }}C++ edition :
#include<bits/stdc++.h>using namespace std;class Solution {public: bool isPalindrome(string s) { string str; for(char ch : s){ // Consider only alphabetic and numeric characters if(isalnum(ch)){ // Convert characters to lowercase str += tolower(ch); } } /** * c.rbegin() Returns an inverse iterator , It points to the container c Last element of * c.rend() Returns an inverse iterator , It points to the container c The position in front of the first element of */ string str2(str.rbegin(), str.rend()); // Judge whether it is a palindrome string return str == str2; }};int main() { Solution s; cout << (s.isPalindrome("A man, a plan, a canal: Panama") ?"true":"false")<< endl; return 0;}The above is to verify the whole content of the palindrome string
Copyright notice :
Original Blogger : Cowherd Conan
Personal blog links :https://www.keafmd.top/
If it helps you , Thank you for clicking on == One key, three links == Support !
[ ha-ha ][ Huai Quan ]

come on. !
Joint efforts !
Keafmd
You can see it here , You know the following , Let's make progress together !
边栏推荐
- 兼顾企业抗疫和发展的5个解决方案,来自IBM
- MIPS汇编语言学习-01-两数求和以及环境配置、如何运行
- 【mysql学习笔记24】索引设计原则
- Case driven: a detailed guide from getting started to mastering shell programming
- Express模板引擎
- ORACLE中dbms_output.put_line输出问题的解决过程
- [JS] Fibonacci sequence implementation (recursion and loop)
- What are the benefits of this PMP certificate?
- R language ggplot2 visualization: the patchwork package is used to customize and combine the three ggplot2 visualization results to form a composite graph. After the horizontal combination of two sub
- BatchNorm2d原理、作用及其pytorch中BatchNorm2d函数的参数讲解
猜你喜欢

Jackie Chan and fast brand, who is the Savior of Kwai?

MIPS汇编语言学习-01-两数求和以及环境配置、如何运行

Classmate Zhang hasn't learned to be an anchor yet

老板嘱咐了三遍:低调、低调、低调

Q-Tester 3.2:适用于开发、生产和售后的诊断测试软件

【算法篇】刷了两道大厂面试题,含泪 ”重学数组“

蔚来潜藏的危机:过去、现在到未来

After QQ was stolen, a large number of users "died"
![[MySQL learning notes 23] index optimization](/img/08/644fddf2521b47de41dff99ebaad56.png)
[MySQL learning notes 23] index optimization

Leetcode 705. Design hash collection
随机推荐
Q-tester 3.2: applicable to development, production and after-sales diagnostic test software
浪擎与浪潮,一个从OEM到价值共生的生态样板
Li Kou today's question -522 Longest special sequence
云杉网络DeepFlow帮助5G核心网和电信云构建可观测性
[collection of excellent articles on Digital IC] nearly 500 articles | learning route | basic knowledge | interface | bus | scripting language | chip job search | security | EDA | tools | low power de
叮!Techo Day 腾讯技术开放日如约而至!
买卖股票的最佳时机
力扣今日题-522. 最长特殊序列
Leetcode 48. Rotate image (yes, resolved)
美国乔布斯,殁了;中国乔布斯,卖了
New offline retail stores take off against the trend, and consumption enthusiasm under the dark cloud of inflation
Could you tell me whether the batch addition of Oracle such as insert all was not blocked?
使用Karmada实现Helm应用的跨集群部署
兼顾企业抗疫和发展的5个解决方案,来自IBM
Oracle11g数据库使用expdp每周进行数据备份并上传到备份服务器
Leetcode (665) -- non decreasing column
web Worker 轮询请求
WPF 视频硬解码渲染播放(无空域)(支持4K、8K、高帧率视频)
2022年最新PyCharm激活破解码永久_详细安装教程(适用多版本)
R language ggplot2 visualization: the patchwork package is used to customize and combine the three ggplot2 visualization results to form a composite graph. After the horizontal combination of two sub