From 9c76a62865d105579f82c4c0104c6fcf33a19f99 Mon Sep 17 00:00:00 2001 From: YOUNGJIN NA <120540450+ppxyn1@users.noreply.github.com> Date: Tue, 16 Dec 2025 21:06:21 +0900 Subject: [PATCH] [:solved] #222 --- valid-parentheses/ppxyn1.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 valid-parentheses/ppxyn1.py diff --git a/valid-parentheses/ppxyn1.py b/valid-parentheses/ppxyn1.py new file mode 100644 index 000000000..191bb518d --- /dev/null +++ b/valid-parentheses/ppxyn1.py @@ -0,0 +1,22 @@ +# idea : stack + +class Solution: + def isValid(self, s: str) -> bool: + mapping = {"(": ")", "{": "}", "[": "]"} + stack = [] + + for ch in s: + if ch in mapping: + stack.append(ch) + else: + if not stack: + return False + if mapping[stack.pop()] != ch: + return False + if stack: + return False + + return True + + +