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

首頁 > 學院 > 開發設計 > 正文

LeetCode 125. Valid Palindrome

2019-11-14 09:18:18
字體:
來源:轉載
供稿:網友

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

分析 將字符串轉換為小寫格式,便于統一比較。 自動跳過非數字字母的字符。

代碼

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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大余县| 台北市| 岗巴县| 贵阳市| 清徐县| 永川市| 庆城县| 武鸣县| 溆浦县| 隆子县| 石河子市| 巫山县| 宝清县| 本溪| 汽车| 东光县| 游戏| 偏关县| 黄冈市| 扬州市| 平度市| 广德县| 忻州市| 仪陇县| 三台县| 临泉县| 蓬莱市| 江川县| 潜山县| 萨嘎县| 肃南| 新蔡县| 瑞丽市| 中山市| 广汉市| 资兴市| 当涂县| 司法| 秭归县| 庆元县| 玉门市|