Skip to content

Commit b7fd7ff

Browse files
authored
Merge pull request #1271 from ivan1016017/may15
adding update
2 parents 25af909 + 3e88eed commit b7fd7ff

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
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+
from collections import defaultdict
4+
5+
class Solution:
6+
def wordPattern(self, pattern: str, s: str) -> bool:
7+
8+
dic_answer = defaultdict(str)
9+
10+
words = s.split(' ')
11+
12+
if len(words) != len(pattern) or len(set(words)) != len(set(pattern)):
13+
return False
14+
else:
15+
for k, v in enumerate(words):
16+
if v in dic_answer:
17+
if dic_answer[v] != pattern[k]:
18+
return False
19+
else:
20+
dic_answer[v] = pattern[k]
21+
22+
return True
23+

tests/test_150_questions_round_12/test_invert_binary_tree_round_12.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from my_project.interviews.top_150_questions_round_12\
2+
from src.my_project.interviews.top_150_questions_round_12\
33
.invert_binary_tree import Solution, TreeNode
44

55
class InvertTreeTestCase(unittest.TestCase):
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_16\
3+
.word_pattern import Solution
4+
5+
class WordPatternTestCase(unittest.TestCase):
6+
7+
def test_is_word_pattern(self):
8+
solution = Solution()
9+
output = solution.wordPattern(pattern="abba", s="dog cat cat dog")
10+
self.assertTrue(output)
11+
12+
def test_is_no_word_pattern_one(self):
13+
solution = Solution()
14+
output = solution.wordPattern(pattern="abc", s="dog cat cat fish")
15+
self.assertFalse(output)
16+
17+
def test_is_no_word_pattern_two(self):
18+
solution = Solution()
19+
output = solution.wordPattern(pattern="aa", s="dog cat cat fish")
20+
self.assertFalse(output)

tests/test_150_questions_round_7/test_binary_tree_round_7.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from my_project.interviews.top_150_questions_round_7\
2+
from src.my_project.interviews.top_150_questions_round_7\
33
.invert_binary_tree import TreeNode, Solution
44

55
class InvertTreeTestCase(unittest.TestCase):

tests/test_150_questions_round_9/test_number_of_bits_round_9.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from my_project.interviews.top_150_questions_round_9\
2+
from src.my_project.interviews.top_150_questions_round_9\
33
.number_of_one_bits import Solution
44

55
class NumberOfOnesTestCase(unittest.TestCase):

0 commit comments

Comments
 (0)