Re: [LeetCode] 刷到面試 Grind169 C++
125. Valid Palindrome easy題
也是雙指針的題
這次有想到怎麼解
但判斷大小寫的函數沒用過
所以還是有上網查
class Solution {
public:
bool isPalindrome(string s) {
int start = 0;
const int n = s.length();
int end = n-1;
while(start<end){
while(start<end && !isalnum(s[start])) start++;
while(start<end && !isalnum(s[end])) end--;
if(tolower(s[start])!=tolower(s[end])) return false;
start++;
end--;
}
return true;
}
};
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.136.220 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1678850748.A.640.html
推
03/15 11:26,
2年前
, 1F
03/15 11:26, 1F
討論串 (同標題文章)
完整討論串 (本文為第 5 之 14 篇):