Valid Parentheses

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

  1. Open brackets must be closed by the same type of brackets.

  2. Open brackets must be closed in the correct order.

์ž๋ฃŒ๊ตฌ์กฐ : Stack ๊ณผ Map

์•Œ๊ณ ๋ฆฌ์ฆ˜ 0.Map๊ณผ Stack ์ƒ์„ฑํ•œ๋‹ค. - Map(key,value) = Map( '(' , ')' ) 1. open bracket์ด ๋‚˜์˜ค๋ฉด ์Šคํƒ์— ๋„ฃ๋Š”๋‹ค. 2. closed bracket์ด ๋‚˜์˜ค๋ฉด 1๊ณผ ์ƒ์‘ํ•˜๋Š” ๊ฒƒ์ธ์ง€ ํ™•์ธํ•œ๋‹ค. 2. ์Šคํƒ์ด ๋น„์–ด์žˆ๋‹ค๋ฉด validํ•˜๋‹ค. - .empty()๋กœ true ๋ฆฌํ„ด

Last updated