알고리즘/leetcode

[Python] leetcode Valid Palindrome

정찡이 2022. 3. 8. 01:12
728x90

1. 문제 링크

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

 

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

 

2. 문제 요약

문자열이 팰린드롬(뒤집어도 같은 말) 인지 확인하자. 
* 대소문자를 구분하지 않고, 영문자와 숫자만 대상으로 함 

3. 아이디어 정리

4. 문제 풀이

4-1. 내 풀이

class Solution:
    def isPalindrome(self, s: str) -> bool:
        new = ''
        for c in s:
            if c.isalnum():
                new += c.lower()
        return new[:] == new[::-1]

5. 결론 및 느낀 점

  • 문자열 다루기로 편하게 구현 가능 
  • 그 외 방법은 데크로 하나씩 pop 하면서 확인한다.