精華區beta Marginalman 關於我們 聯絡資訊
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
DreaMaker167: 大師 03/15 11:26