# Valid Parentheses

Given a string containing just the characters `'('`

, `')'`

, `'{'`

, `'}'`

, `'['`

and `']'`

, determine if the input string is valid.

**Examples**

The brackets must close in the correct order, `"()"`

and `"()[]{}"`

are all valid but `"(]"`

and `"([)]"`

are not.

## Solution

This problem can be easily solved by using a stack, as follows:

- Scan each character of the string from left to right
- If the current character is
`'('`

,`'{'`

, or`'['`

, put it into the stack - If the current character is
`')'`

,`'}'`

, or`']'`

:- Pop what is on the top of the stack
- Compare what is pop and the current character. If they donâ€™t match, return false

The Java implementation of the algorithm follows.