Leetcode[125]-Valid Palindrome
来源:互联网 发布:mac excel单元格内换行 编辑:程序博客网 时间:2024/06/05 03:30
Link: https://leetcode.com/problems/valid-palindrome/
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.
思路:定义两个标示符,一个指向字符串前面,一个指向字符串末尾,如果前后位置的字符不是字母或是数字,则直接跳过该字符,如果是大写,则转换成小写再比较,如果碰到不匹配的直接返回false。
Code(C++):
class Solution {public: bool isPalindrome(string s) { int length = s.length(); if(length == 0){ return true; } int i = 0, j = length-1; while(i <= j){ if(!isStr(s[i])) i++; else if(!isStr(s[j])) j--; else if(s[i++] != s[j--]) return false; } return true; } bool isStr(char &a){ if(a >= '0' && a <= '9' ) { return true; }else if(a >= 'a' && a <= 'z' ) { a -= 32; return true; } else if(a >= 'A' && a <= 'Z' ) { return true; } return false; }};
0 0
- LeetCode 125: Valid Palindrome
- LeetCode 125 Valid Palindrome
- LeetCode: Valid Palindrome [125]
- leetcode 125-Valid Palindrome
- [leetcode 125] Valid Palindrome
- leetCode #125 Valid Palindrome
- [LeetCode 125] Valid Palindrome
- LeetCode 125 Valid Palindrome
- leetcode-125 Valid Palindrome
- leetcode || 125、Valid Palindrome
- LeetCode---(125) Valid Palindrome
- Leetcode[125]-Valid Palindrome
- leetcode[125]:Valid Palindrome
- Leetcode# 125 Valid Palindrome
- leetcode 125: Valid Palindrome
- leetcode: (125) Valid Palindrome
- [Leetcode]#125 Valid Palindrome
- LeetCode 125 Valid Palindrome
- iOS 调用微信
- Yii2.0 依赖注入(DI)和依赖注入容器的原理
- 图兰朵计划:意大利艺术类院校九大优势
- DLX模板
- jQuery与Java实现图片的剪切
- Leetcode[125]-Valid Palindrome
- iOS开发~CocoaPods使用详细说明
- Asp.net安全架构之1:xss(跨站脚本)
- sql_server set identity_insert_on 用法总结
- mysql使用索引优化order排序
- Ubuntu-15.04-64位配置安卓开发环境
- Bash Shell 的管道命令
- 开始我的CSDN之旅
- 小文件问题