Skip to content

Commit a37336d

Browse files
authored
Merge pull request #1441 from ivan1016017/october31
adding algo
2 parents e95fb81 + eba673f commit a37336d

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
import re
4+
5+
class Solution:
6+
def isPalindrome(self, s: str) -> bool:
7+
8+
# To lowercase
9+
s = s.lower()
10+
11+
# Remove non-alphanumerical characters
12+
s = re.sub(pattern='[^a-zA-Z0-9]', repl='', string=s)
13+
14+
# Find if it is palindrome or not
15+
16+
len_s = len(s)
17+
18+
for i in range(len_s//2):
19+
20+
if s[i] != s[len_s - 1 - i]:
21+
return False
22+
23+
return True
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
4+
class Solution:
5+
def lengthOfLastWord(self, s: str) -> int:
6+
7+
lst_s = s.split()
8+
9+
return len(lst_s[-1])
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_21\
3+
.length_of_last_word import Solution
4+
5+
class LengthLastWordTestCase(unittest.TestCase):
6+
7+
def test_length_last_word(self):
8+
solution = Solution()
9+
output = solution.lengthOfLastWord(s="Hello World")
10+
target = 5
11+
self.assertEqual(output, target)

0 commit comments

Comments
 (0)