3.1ValidPalindrome
来源:互联网 发布:韩国碧尔缇希 知乎 编辑:程序博客网 时间:2024/05/11 15:51
Notes: 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. Solution: traverse from both side. */思路:判断一个字符串是不是回文,看字符串是不是以中间位置对称,对称的话就是回文,否则不是。
#include <cctype> // needed for isalnum(), isupper() and tolower(). /**** isalnum()用来判断是不是字符或数字,isupper() 判断是不是大写字母, tolower()将大写字母转换成小写字母*****/class Solution {public: bool isPalindrome(string s) { for (int i = 0, j = s.size() - 1; i < j; ++i, --j) { while (i < j && !isalnum(s[i])) i++; while (i < j && !isalnum(s[j])) j--; if (tolower(s[i]) != tolower(s[j])) return false; } return true; }};
0 0
- 3.1ValidPalindrome
- ValidPalindrome
- leetcode125.ValidPalindrome
- LeetCode(125)ValidPalindrome
- 3.1
- 3.1
- 3.1
- 3.1
- 3.1
- 3.1
- 3.1
- 3.1
- eclipse 3.1
- 3.1~3.3
- ACDSee 3.1
- hibernate 3.1
- Android 3.1
- 3.1-3.4
- 异常
- Singular Value Thresholding (SVT) 奇异值阈值
- LCD驱动分析(三): framebuffer驱动的注册
- java webservice 学习
- git如何clone所有的远程分支
- 3.1ValidPalindrome
- 海量数据处理---Trie树(字典树)
- Linux3.X下的Samsung MFC(Multi Format Codec) Firmware
- Java基础(极客)——15、Java面向对象多态性
- hdu-1142-A Walk Through the Forest-最短路+记忆化搜索
- EXCEL内容匹配宏程序
- html中div居中并移动
- 求助 利用广播监听 手机拨号 在虚拟机上能运行 真机没法应
- C++设置全局变量