valid-palindrome leetcode C++
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example, "A man, a plan, a canal: Panama"is a palindrome. "race a car"is not a palindrome.
Note: Have you consider that the string might be empty? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.
C++
class Solution {
bool isAlphaNum(char &ch) {
if (ch >= 'a' && ch <= 'z') return true;
if (ch >= 'A' && ch <= 'Z') return true;
if (ch >= '0' && ch <= '9') return true;
return false;
}
public:
bool isPalindrome(string s) {
int left = 0, right = s.size() - 1 ;
while (left < right) {
if (!isAlphaNum(s[left])) ++left;
else if (!isAlphaNum(s[right])) --right;
else if ((s[left] + 32 - 'a') %32 != (s[right] + 32 - 'a') % 32) return false;
else {
++left; --right;
}
}
return true;
}
bool isPalindrome2(string s){
if("" == s) return true;
int left = 0;
int right = s.size() - 1;
while (left<right){
if(!isAlphaNum(s[left])) left++;
else if (!isAlphaNum(s[right])) right--;
else if ((s[left] + 32 - 'a') %32 != (s[right] + 32 - 'a') % 32) return false;
else { left++; right--;}
}
return true;
}
};
valid-palindrome leetcode C++的更多相关文章
- Valid Palindrome [LeetCode]
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- Valid Palindrome leetcode java
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...
- Valid Palindrome ---- LeetCode 125
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LeetCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LeetCode]题解(python):125 Valid Palindrome
题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...
- [Leetcode][JAVA] Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【LeetCode OJ】Valid Palindrome
Problem Link: http://oj.leetcode.com/problems/valid-palindrome/ The following two conditions would s ...
- LeetCode——Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LeetCode] Valid Palindrome II 验证回文字符串之二
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- 【一天一道LeetCode】#125. Valid Palindrome
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
随机推荐
- jsp页面动态获取系统时间
最近在做练习时碰到了这样一个问题:"读者选择查询图书相应信息,跳转到书目的详细信息界面,当可借阅数量大于零,点击借阅按钮,提示用户借阅成功,并显示归还日期(三个月),否则提示用户该书可借阅数 ...
- DevOps与CICD简介
整体知识点 ·Devops与CI/CD简介 ·Gitlab安装与Git命令使用 ·Gitlab实现持续集成 ·Gitlab实现分支管理 ·Jenkins简介及安装 ·Jenkins插件管理及基础配置 ...
- ARC106E-Medals【hall定理,高维前缀和】
正题 题目链接:https://atcoder.jp/contests/arc106/tasks/arc106_e 题目大意 \(n\)个员工,第\(i\)个在\([1,A_i]\)工作,\([A_i ...
- ❤️Python接口自动化,一文告诉你连接各大【数据库】建议收藏❤️
@ 目录 前言 常见数据库 Mysql Oracle sql-server PostgreSQL MongoDB Redis 前言 相信很多小伙伴在使用python进行自动化测试的时候,都会涉及到数据 ...
- Matlab 速记
链接:https://zhuanlan.zhihu.com/p/370259237 % 1.进度提醒 f = waitbar(0,'1','Name','进度'); set(f,'color','w' ...
- Skywalking-09:OAL原理——如何通过动态生成的Class类保存数据
OAL 如何通过动态生成的 Class 类,保存数据 前置工作 OAL 如何将动态生成的 SourceDispatcher 添加到 DispatcherManager // org.apache.sk ...
- 关于docker复现vulhub环境的搭建
原本想用docker复现一下vul的漏洞. 装docker过程中遇到了很多问题, 昨天熬夜到凌晨三点都没弄完. 中午又找了找原因,终于全部解决了, 小结一下. 0x01 镜像 去官方下载了centos ...
- Go的Select
Go 的通道有两种操作方式,一种是带 range 子句的 for 语句,另一种则是 select 语句,它是专门为了操作通道而存在的.这里主要介绍 select 的用法. 一.select的语法 se ...
- cadvisor+prometheus+alertmanager+grafana完成容器化监控告警(一)
一.概况 1.拓扑图 2.名词解释 Grafana 可视化监控容器运行情况 Prometheus: 开源系统监视和警报工具包 Alertmanager 一个独立的组件,负责接收并处理来自Prometh ...
- macbook air m1上传文件到github
一,首先安装git,打开ssh文件里的id_rsa.pub,然后复制所有内容. 二,github上申请自己的账号,右上角settings里选择SSH and GPG keys,点击new ssh ke ...