Skip to content

Commit 68647ca

Browse files
committed
adding valid anagram
1 parent b7fd7ff commit 68647ca

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
4+
5+
class Solution:
6+
def isAnagram(self, s: str, t: str) -> bool:
7+
8+
lst_s = [c for c in s]
9+
lst_t = [c for c in t]
10+
11+
lst_s.sort()
12+
lst_t.sort()
13+
14+
return lst_s == lst_t
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_16\
3+
.valid_anagram import Solution
4+
5+
class ValidAnagramTestCase(unittest.TestCase):
6+
7+
def test_is_valid_anagram(self):
8+
solution = Solution()
9+
output = solution.isAnagram(s="anagram", t="nagaram")
10+
self.assertTrue(output)
11+
12+
13+
def test_is_no_valid_anagram(self):
14+
solution = Solution()
15+
output = solution.isAnagram(s="rat", t="car")
16+
self.assertFalse(output)

0 commit comments

Comments
 (0)