日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

LeetCode OJ - Valid Palindrome

發(fā)布時間:2023/12/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LeetCode OJ - Valid Palindrome 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目:

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.

解題思路:

設(shè)置前后兩個指針,依次比較,若不相等則表明不是回文串。注意調(diào)過不是字母的字符。

代碼:

class Solution { public:bool isPalindrome(string s) {if (s.empty()) return true;for (int i = 0, j = s.length() - 1; i <= j; i++, j--) {while (i < s.length() && !((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= '0' && s[i] <= '9'))) i++;while (j >= 0 && !((s[j] >= 'a' && s[j] <= 'z') || (s[j] >= 'A' && s[j] <= 'Z') || (s[j] >= '0' && s[j] <= '9'))) j--;if (i > j) break;if (s[i] != s[j] && s[i] != s[j] + 32 && s[i] + 32 != s[j]) {return false;}}return true;} };

?

轉(zhuǎn)載于:https://www.cnblogs.com/dongguangqing/p/3727758.html

總結(jié)

以上是生活随笔為你收集整理的LeetCode OJ - Valid Palindrome的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。