Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List, Union, Collection, Mapping, Optional
from abc import ABC, abstractmethod

class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:

answer = dict()

for k, v in enumerate(nums):

if v in answer:
return [answer[v], k]
else:
answer[target - v] = k

return []
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import List, Union, Collection, Mapping, Optional
from abc import ABC, abstractmethod
import re

class Solution:
def isPalindrome(self, s: str) -> bool:

# To lowercase
s = s.lower()

# Remove non-alphanumeric characters
s = re.sub(pattern='[^a-zA-Z0-9]', repl='', string=s)

# Determine if palindrome or not

len_s = len(s)

for i in range(len_s//2):

if s[i] != s[len_s - 1 -i]:
return False

return True
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import List, Union, Collection, Mapping, Optional
from abc import ABC, abstractmethod

class Solution:
def isAnagram(self, s: str, t: str) -> bool:

lst_s = [c for c in s]
lst_t = [c for c in t]

lst_s.sort()
lst_t.sort()

return lst_s == lst_t
16 changes: 16 additions & 0 deletions tests/test_150_questions_round_21/test_valid_anagram_round_21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest
from src.my_project.interviews.top_150_questions_round_21\
.valid_anagram import Solution

class ValidAnagramTestCase(unittest.TestCase):

def test_is_valid_anagram(self):
solution = Solution()
output = solution.isAnagram(s="anagram", t="nagaram")
self.assertTrue(output)


def test_is_no_valid_anagram(self):
solution = Solution()
output = solution.isAnagram(s="rat", t="car")
self.assertFalse(output)