[LeetCode][Python3] 125. Valid Palindrome
2018. 10. 17. 01:03 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/valid-palindrome/description/
My Solution :
class Solution:
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
i = 0
j = len(s)-1
while i < j:
while i < j and not s[i].isalnum():
i += 1
while i < j and not s[j].isalnum():
j -= 1
if s[i].lower() != s[j].lower():
return False
i += 1
j -= 1
return True
Comment :
Python str class는 isalnum, isalpha, isdigit, islower, isupper 등의 편리한 method를 가지고 있다.
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 171. Excel Sheet Column Number (0) | 2018.11.03 |
---|---|
[LeetCode][Python3] 122. Best Time to Buy and Sell Stock II (0) | 2018.11.03 |
[LeetCode][Python3] 88. Merge Sorted Array (0) | 2018.11.03 |
[LeetCode][Python3] 118. Pascal's Triangle (0) | 2018.10.17 |
[LeetCode][Python3] 66. Plus One (0) | 2018.10.15 |
[LeetCode][Python3] 543. Diameter of Binary Tree (0) | 2018.10.09 |
[LeetCode][Python3] 617. Merge Two Binary Trees (0) | 2018.10.08 |
[LeetCode][Python3] 581. Shortest Unsorted Continuous Subarray (0) | 2018.10.08 |
최근에 달린 댓글 최근에 달린 댓글