From 86af7e8e048f8e049c59eef5e0dc96c8a1768189 Mon Sep 17 00:00:00 2001 From: manikonda-anjali Date: Sun, 2 Nov 2025 15:26:06 +0530 Subject: [PATCH 1/2] Added bubble sort implementation in Python --- algorithms/valid-parentheses.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 algorithms/valid-parentheses.py diff --git a/algorithms/valid-parentheses.py b/algorithms/valid-parentheses.py new file mode 100644 index 000000000000..19e152739ed3 --- /dev/null +++ b/algorithms/valid-parentheses.py @@ -0,0 +1,12 @@ +class Solution: + def isValid(self, s): + stack = [] + mapping = {')': '(', '}': '{', ']': '['} + for char in s: + if char in mapping: + top = stack.pop() if stack else '#' + if mapping[char] != top: + return False + else: + stack.append(char) + return not stack From ea4ac08939a3d80740c25a709e0a50a6681c7368 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 2 Nov 2025 10:02:58 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- algorithms/valid-parentheses.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/algorithms/valid-parentheses.py b/algorithms/valid-parentheses.py index 19e152739ed3..e7fa7b2443de 100644 --- a/algorithms/valid-parentheses.py +++ b/algorithms/valid-parentheses.py @@ -1,10 +1,10 @@ class Solution: def isValid(self, s): stack = [] - mapping = {')': '(', '}': '{', ']': '['} + mapping = {")": "(", "}": "{", "]": "["} for char in s: if char in mapping: - top = stack.pop() if stack else '#' + top = stack.pop() if stack else "#" if mapping[char] != top: return False else: