-
[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
'알고리즘' 카테고리의 다른 글
[LeetCode] Single Number (0) 2019.12.06 [LeetCode] Word Ladder (0) 2019.12.06 [LeetCode] Binary Tree Maximum Path Sum (0) 2019.12.05 [LeetCode] Best Time to Buy and Sell Stock II (0) 2019.12.04 [LeetCode] Best Time to Buy and Sell Stock (0) 2019.12.04