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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

LeetCode 125. Valid Palindrome

2019-11-11 07:25:44
字體:
供稿:網(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)一比較。 自動(dò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ā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 清徐县| 祁阳县| 文山县| 哈密市| 广平县| 随州市| 呈贡县| 沈丘县| 禹州市| 莎车县| 桦南县| 吐鲁番市| 神农架林区| 汉沽区| 岢岚县| 林西县| 固阳县| 永顺县| 东台市| 临朐县| 安远县| 林芝县| 抚州市| 曲松县| 永兴县| 剑阁县| 涞水县| 太和县| 蕉岭县| 全州县| 泽库县| 石泉县| 松桃| 阿合奇县| 和平区| 子长县| 江门市| 油尖旺区| 沙洋县| 兴和县| 开平市|