[LeetCode] 125. Valid Palindrome
来源:互联网 发布:淘宝如何开天猫店 编辑:程序博客网 时间:2024/06/05 04:25
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.
// naiveclass Solution {public: bool isPalindrome(string s) { int i = 0, j = (int)s.size() - 1; while (i < j) { if (!isalnum(s[i])) { i++; continue; } if (!isalnum(s[j])) { j--; continue; } if (tolower(s[i++]) != tolower(s[j--])) return false; } return true; }};
// much betterclass Solution {public: bool isPalindrome(string s) { for (int i = 0, j = (int)s.size() - 1; i < j; i++, j--) { while (!isalnum(s[i]) && i < j) i++; while (!isalnum(s[j]) && i < j) j--; if (tolower(s[i]) != tolower(s[j])) return false; } return true; }};
阅读全文
0 0
- [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
- 125. Valid Palindrome LeetCode
- 【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
- [k8s]calico证书
- GIT实现部分提交
- Android 自定义控件 轻松实现360软件详情页
- poj 2503 Babelfish (map)
- 深机笔记
- [LeetCode] 125. Valid Palindrome
- LeetCode 506. Relative Ranks
- 自定义imageview中的canvas.drawBitmap方法
- JS-判断是否为微信扫码
- Android 自定义控件 优雅实现元素间的分割线 (支持3.0以下)
- 安卓百分比布局
- latex公式中的空格如何表示?
- 面试笔试准备和思考
- 线下活动【深圳】用Leangoo做Scrum敏捷开发实战课(免费)