코테준비 - Valid Palindrome

정상화·2023년 2월 26일

LeetCode

목록 보기
122/222

Valid Palindrome

class Solution {
public:
    bool isPalindrome(string s) {
        string converted = "";
        for (auto &c: s) {
            if (('a' <= c && c <= 'z') || ('0' <= c && c<= '9')) {
                converted += c;
            } else if ('A' <= c && c <= 'Z') {
                converted += (c - ('A' - 'a'));
            }
        }
        string copied = converted;
        std::reverse(copied.begin(), copied.end());
        return copied == converted;
    }
};
profile
백엔드 희망

0개의 댓글