DSAMediumStack
Valid Parentheses (Stack)
đ Problem
Given a string containing only '(', ')', '{', '}', '[' and ']', determine if the brackets are balanced and correctly nested.
đ§ Approach
Use a stack. Go through the string character by character â whenever you see an opening bracket, push it. Whenever you see a closing bracket, check if the top of the stack is its matching opening bracket; if yes, pop it, if no, the string is invalid. At the end, the string is valid only if the stack is empty.