🧮
Valid Parentheses
Valid Parentheses보통 알고리즘 +20pts
Problem
Write a function that checks if a string of parentheses is valid.
Examples
Input:
isValid("(())")Output:
trueInput:
isValid("(()")Output:
falseExplanation
이 문제는 **스택(Stack)** 자료구조를 활용한 괄호 검증 알고리즘을 학습합니다. 코딩 인터뷰의 클래식 문제입니다. **스택을 사용하는 이유** 괄호는 LIFO(Last In, First Out) 특성을 가집니다. 가장 최근에 열린 괄호가 먼저 닫혀야 합니다. **알고리즘 전략** 1. 여는 괄호 → 대응하는 닫는 괄호를 스택에 push 2. 닫는 괄호 → 스택에서 pop하여 일치 확인 3. 끝까지 순회 후 스택이 비어있으면 유효 **pairs 객체의 역할** `{ '(': ')', '[': ']', '{': '}' }`...
View detailed explanation →Key Concepts
스택 자료구조 LIFO 원리 괄호 매칭 유효성 검사
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.