From 1f9f95b0c3401a8a4187f2c8620b41fdf6fd4e03 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 16 Apr 2025 03:57:04 -0600 Subject: [PATCH] adding algo --- .../valid_parentheses.py | 18 ++++++++++++++++++ .../test_valid_parentheses_round_15.py | 0 2 files changed, 18 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_15/valid_parentheses.py create mode 100644 tests/test_150_questions_round_15/test_valid_parentheses_round_15.py diff --git a/src/my_project/interviews/top_150_questions_round_15/valid_parentheses.py b/src/my_project/interviews/top_150_questions_round_15/valid_parentheses.py new file mode 100644 index 00000000..c363c558 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_15/valid_parentheses.py @@ -0,0 +1,18 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def isValid(self, s): + + dic_parentheses = {'(':')','[':']','{':'}'} + check_list = list() + + for p in s: + if p in dic_parentheses: + check_list.append(p) + else: + if len(check_list) == 0 \ + or p != dic_parentheses[check_list.pop()]: + return False + + return len(check_list) == 0 diff --git a/tests/test_150_questions_round_15/test_valid_parentheses_round_15.py b/tests/test_150_questions_round_15/test_valid_parentheses_round_15.py new file mode 100644 index 00000000..e69de29b