国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 景宁| 连云港市| 开鲁县| 岢岚县| 右玉县| 逊克县| 莒南县| 涪陵区| 保定市| 塔城市| 蓝山县| 黔西县| 湖口县| 潮州市| 皋兰县| 洪洞县| 阿拉善右旗| 九龙城区| 凤阳县| 志丹县| 原平市| 闽清县| 类乌齐县| 广州市| 新郑市| 姚安县| 瑞安市| 临潭县| 东丰县| 临沂市| 大悟县| 耒阳市| 北碚区| 什邡市| 南城县| 大厂| 甘肃省| 滨海县| 葫芦岛市| 哈巴河县| 镇康县|