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

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

LeetCode 125. Valid Palindrome

2019-11-11 06:47:39
字體:
來源:轉載
供稿:網友

描述 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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 竹北市| 甘肃省| 凤翔县| 咸丰县| 原阳县| 泸溪县| 郸城县| 上高县| 体育| 扬州市| 云南省| 图木舒克市| 长治市| 县级市| 保定市| 安国市| 新津县| 耒阳市| 景德镇市| 松原市| 玛纳斯县| 鹿邑县| 华阴市| 石首市| 缙云县| 德江县| 新巴尔虎左旗| 宁乡县| 贵州省| 南木林县| 三门峡市| 东乡县| 本溪市| 景东| 巴林左旗| 诏安县| 察隅县| 手游| 泰宁县| 福泉市| 鹤岗市|