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
'알고리즘 > LeetCode' 카테고리의 다른 글
[LeetCode/easy] Valid Anagram (0) | 2022.08.12 |
---|---|
[LeetCode/easy] Isomorphic Strings (0) | 2022.08.12 |
[LeetCode/easy] Add Binary (0) | 2022.08.12 |
[LeetCode/easy] Length of Last Word (0) | 2022.08.12 |
[LeetCode/easy] strStr() (0) | 2022.08.12 |