File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 11# https://neetcode.io/problems/is-palindrome
22
3+ # `isalnum()` method returns True if all the characters are alphanumeric, meaning alphabet letter (a-z) and numbers (0-9).
4+ # `isalpha()` method returns True if all the characters are alphabet letters (a-z).
5+ # `isdigit()` method returns True if all the characters are digits (0-9).
6+ # `islower()` method returns True if all the characters are in lower case.
7+
8+ # Therefore, for this problem, we can use `isalnum()` to check if the character is an alphabet letter or a number.
9+ # However, if we are asked to implement `isalnum()` method, we can use the following code:
10+
11+ # def is_alnum(character: str) -> bool:
12+ # return (
13+ # ord('A') <= ord(character) <= ord('Z') or
14+ # ord('a') <= ord(character) <= ord('z') or
15+ # ord('0') <= ord(character) <= ord('9')
16+ # )
17+
318import unittest
419
520
@@ -34,3 +49,4 @@ class Test(unittest.TestCase):
3449 def test_is_palindrome (self ):
3550 self .assertTrue (is_palindrome ("Was it a car or a cat I saw?" ))
3651 self .assertFalse (is_palindrome ("tab a cat" ))
52+ self .assertFalse (is_palindrome ("0P" ))
You can’t perform that action at this time.
0 commit comments