Member-only story
Day 25 — Valid Parentheses | Blind 75 | Java
1 min readAug 23, 2026
Question
Given a string s containing only ()[]{}, determine if the string is valid.
A string is valid if:
- Every opening bracket has a matching closing bracket.
- Brackets are closed in the correct order.
- Brackets match the correct type.
Input & Output
Input: s = "()"
Output: trueInput: s = "()[]{}"
Output: trueInput: s = "(]"
Output: falseInput: s = "([)]"
Output: falseInput: s = "([])"
Output: trueApproach
We use a Stack because brackets follow Last In, First Out (LIFO).
- If we see an opening bracket, push it into the stack.
- If we see a closing bracket, check whether it matches the top of the stack.
- If it doesn’t match, return
false. - At the end, the stack must be empty.
We use a HashMap to store the matching pairs:
) → (
} → {
] → [Code
import java.util.*;
class Solution {
public boolean isValid(String s) {
Deque<Character> stack = new ArrayDeque<>();
Map<Character, Character> resultMap = new HashMap<>();
resultMap.put(')', '(');
resultMap.put('}', '{')…





