LeetCode125. 驗證迴文串

Ember_Sky發表於2020-09-27
//125. 驗證迴文串
class Solution {
public:
  bool isPalindrome(string s) {
    string ns;
    for (auto x : s) {
      if ('A' <= x && x <= 'Z')ns += (char)(x - 'A' + 'a');
      else if ('a' <= x && x <= 'z') ns += x;
      else if ('0' <= x && x <= '9') ns += x;
    }
    for (int i = 0; i * 2 < ns.size(); i++)
      if (ns[i] != ns[ns.size() - 1 - i]) return false;
    return true;
  }
};

相關文章