国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

LeetCode 125. Valid Palindrome

2019-11-11 07:30:42
字體:
供稿:網(wǎng)友

描述 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.

分析 將字符串轉(zhuǎn)換為小寫格式,便于統(tǒng)一比較。 自動跳過非數(shù)字字母的字符。

代碼

class Solution {public: bool isPalindrome(string s) { transform(s.begin(), s.end(), s.begin(), ::tolower); auto left = s.begin(), right = prev(s.end()); while (left < right) { if (!::isalnum(*left)) ++left; else if (!::isalnum(*right)) --right; else if (*left != *right) return false; else { ++left; --right; } } return true; }};
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 金乡县| 常德市| 泰宁县| 阿坝| 太湖县| 隆尧县| 辛集市| 宝丰县| 天峻县| 连云港市| 色达县| 玛纳斯县| 朝阳市| 丽水市| 江都市| 韶关市| 滁州市| 长治县| 平湖市| 武安市| 建水县| 舞钢市| 师宗县| 诏安县| 车险| 东至县| 增城市| 新野县| 泌阳县| 洛隆县| 隆昌县| 图木舒克市| 柘荣县| 九台市| 南开区| 浦江县| 兴和县| 枣阳市| 大厂| 车致| 巴马|