알고리즘/LeetCode

[LeetCode/easy] Valid Palindrome

녕이 2022. 8. 12. 16:55
728x90

 

https://leetcode.com/problems/valid-palindrome/

 

Valid Palindrome - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

문자와 숫자를 포함한 문자열이 팰린드롬이 맞는지 확인하는 문제

대문자는 소문자로 변경해줘서 진행한다.

 

bool isPalindrome(string s) {
    bool answer = true;
    string st;
    for(int i=0; i<s.size(); i++){
        if((s[i] >= 'a' && s[i] <= 'z') || isdigit(s[i]))   st += s[i];
        else if(s[i] >= 'A' && s[i] <= 'Z')                 st += s[i] + 32;
        
    }

    for(int i=0; i<st.size()/2; i++) if(st[i] != st[st.size()-1-i]) return false;
    return answer;
}

 

 

 

728x90