Skip to content

Commit 59b45e9

Browse files
authored
Merge pull request #1419 from ivan1016017/october09
adding updates
2 parents 6ff6d29 + 6b0e840 commit 59b45e9

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
4+
class Solution:
5+
def isValid(self, s):
6+
7+
dic_parentheses = {'(':')','[':']','{':'}'}
8+
9+
check_list = list()
10+
11+
for p in s:
12+
13+
if p in dic_parentheses:
14+
check_list.append(p)
15+
else:
16+
if len(check_list) == 0 or \
17+
dic_parentheses[check_list.pop()] != p:
18+
return False
19+
20+
return len(check_list) == 0
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_20\
3+
.valid_parentheses import Solution
4+
5+
class ValidParenthesesTestCase(unittest.TestCase):
6+
7+
def test_is_valid_parentheses(self):
8+
solution = Solution()
9+
output = solution.isValid(s='()')
10+
self.assertTrue(output)
11+
12+
def test_is_no_valid_parentheses_pattern_1(self):
13+
solution = Solution()
14+
output = solution.isValid(s='(]')
15+
self.assertFalse(output)
16+
17+
def test_is_no_valid_parentheses_pattern_2(self):
18+
solution = Solution()
19+
output = solution.isValid(s='((')
20+
self.assertFalse(output)

0 commit comments

Comments
 (0)