알고리즘

[LeetCode] Valid Palindrome

룰스 2019. 12. 5. 17:00

문제

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid palindrome.

Example 1:

Input: "A man, a plan, a canal: Panama" Output: true

Example 2:

Input: "race a car" Output: false

 

Apporach

isdigit(), isalpha()로 알파벳이나 숫자가 아닌것은 다 거르면서

앞글자 뒷글자를 맞춰보면 된다

isdigit(), isalpha() 두개 쓸 필요 없이 isalnum()이라는게 있다는걸 오늘 처음알았음

 

Code

https://github.com/chi3236/algorithm/blob/master/LeetCode_ValidPalindrome.cpp

 

chi3236/algorithm

Contribute to chi3236/algorithm development by creating an account on GitHub.

github.com