최대 1 분 소요

Link

class Solution:
    def isPalindrome(self, s: str) -> bool:
        filtered_chars = []
        for char in s:
            # point1. method of 'isalnum'
            
            if char.isalnum():  
            # We have to add only 'alphabet' or 'numbers' to the list of 'filtered_chars'
            
            # point2. method of 'lower' for making small letter
                filtered_chars.append(char.lower())  
              # We have to revert to 'small letter' for removing the difference between 'large letter'
              # and 'small letter' to check 'Palindrome'
              
              # point3. method of 'join' for making a attached string
              # 'join' method makes 'list' of 'filtered_chars' to a 'string' attached together
              # by '' infront of the join method.
        filtered_s = ''.join(filtered_chars)
        
        # Checking normal one and reversed one so that 'thet are same'.
        return filtered_s == filtered_s[::-1]

Summary

1.Method of ‘isalnum’

We have to add only ‘alphabet’ or ‘numbers’ to the list of ‘filtered_chars’

2.Method of ‘lower’ for making small letter.

We have to revert to ‘small letter’ for removing the difference between ‘large letter’ and ‘small letter’ to check ‘Palindrome’

3.Method of ‘join’ for making a attached string.

‘join’ method makes ‘list’ of ‘filtered_chars’ to a ‘string’ attached together by ‘’ infront of the join method.

댓글남기기