leetcode 125 valid-palindrome
思路:分别从左low和右high开始比较,如果两个位置的char是数字或者字母,则比较是否相同,如果有一方不是数字或者字符就向中间走,直到是字符或数字时,如果比较后发现不同,跳出循环,直接返回false,否则继续执行,直到low和high相遇,此时表示字符串是回文,返回true。
#include<string>
class Solution {
public:bool ischar(char s){if(s<='z'&&s>='a')return true;if(s<='9'&&s>='0') return true;else return false;}bool isPalindrome(string s) {string str = s;transform(str.begin(),str.end(),str.begin(),::tolower);int length = str.length();int low =0,high = length-1;while(low <=high){while(!ischar(str[low])&&low<=high){low ++;}while(!ischar(str[high])&&low<=high){high--;}if(low>high)break;if(str[low]==str[high]){low++;high--;}else{return false;}}return true;}
};
leetcode 125 valid-palindrome相关推荐
- 【回文串3】LeetCode 125. Valid Palindrome
LeetCode 125. Valid Palindrome Solution1:我的答案 复杂度为O(n)O(n)O(n),写法不是很简练啊. class Solution { public:boo ...
- [勇者闯LeetCode] 125. Valid Palindrome
[勇者闯LeetCode] 125. Valid Palindrome Description Given a string, determine if it is a palindrome, con ...
- LeetCode 125 Valid Palindrome(有效回文)(*)
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/5062 ...
- LeetCode 125. Valid Palindrome
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...
- 125 Valid Palindrome
125 Valid Palindrome 链接:https://leetcode.com/problems/valid-palindrome/ 问题描写叙述: Given a string, dete ...
- 【回文串14】LeetCode 680. Valid Palindrome II
LeetCode 680. Valid Palindrome II Solution1:我的答案 复杂度是O(n)O(n)O(n),不算好啊.. 注意:对于c++中string对象常用的insert( ...
- leetcode python3 简单题125. Valid Palindrome
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百二十五题 (1)题目 英文: Given a string, determin ...
- Leet Code OJ 125. Valid Palindrome [Difficulty: Easy]
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...
- LeetCode OJ - Valid Palindrome
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...
- 125. Valid Palindrome
Title 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 1: 输入: "A man, a pla ...
最新文章
- JBoss Eclipse IDE
- vue项目设置img标签的默认图片
- 4.11-固件映像包 (FIP)
- 图像降噪算法——稀疏表达:K-SVD算法
- Python虚拟环境virtualenv的安装与使用详解(转)
- UI5 Control lazy load mechanism
- 7-6 区间覆盖 (10 分)(思路+详解)Come 宝!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 在text html模版中写js,Rails3使用text/html内容类型而不是text/javascript呈现js.erb模板...
- docker发布spring cloud应用
- Windows Media Player播放器 VC++ 2008
- Naive Operations
- geotools绘制椭圆API
- Mac Android studio 修改历史查看
- 经纬财富:徐州炒白银需要注意哪些技术指标
- Android照片处理——涂鸦和拼图实现
- 计算机专业相关的国家认证,国内认证的计算机证书有哪些?
- 架构设计实践思路:什么是架构,怎么画架构图?
- MIPI CSI-2笔记(12) -- Low Level Protocol(数据加扰,扰码,Data Scrambling)
- vue 基于elementUI、sortablejs的表格拖拽排序
- 【Python百日基础系列】Day02-Python语法基础
热门文章
- Java后端实现websocket与微信小程序端连接简单例子
- C#中的简单工厂设计模式示例
- CentOS配置Nginx官方的Yum源 及yum安装php
- 04-树4. Root of AVL Tree (25)
- webform 组合查询
- php laravel 相关收集
- 2022 SpringBoot的房屋租赁平台 房屋展示平台 留学生房屋租赁平台
- @Responsebody与@RequestBody
- C程序设计--VC++6.0的使用(常用快捷键)
- html文本延迟加载,LazyLoad 延迟加载(按需加载)