From 80935685f3d1739c8891c8b647acfb3751730efe Mon Sep 17 00:00:00 2001 From: YANG YEEUN Date: Tue, 14 Jul 2026 08:50:47 +0900 Subject: [PATCH] =?UTF-8?q?=EC=98=AC=EB=B0=94=EB=A5=B8=20=EA=B4=84?= =?UTF-8?q?=ED=98=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- correct_parenthesis.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 correct_parenthesis.java diff --git a/correct_parenthesis.java b/correct_parenthesis.java new file mode 100644 index 0000000..26e9502 --- /dev/null +++ b/correct_parenthesis.java @@ -0,0 +1,18 @@ +import java.util.*; +class Solution { + boolean solution(String s) { + boolean answer = true; + Deque parenthesis = new ArrayDeque<>(); + Map pair = Map.of(')','('); + for(char c : s.toCharArray()){ + if(c=='('){ + parenthesis.push(c); + }else{ + if(parenthesis.isEmpty() || pair.get(c)!=parenthesis.pop()){ + return false; + } + } + } + return parenthesis.isEmpty(); + } +}