[LeetCode]#20. Valid Parentheses

Environment: Python 3.7

Key technique: .pop, dictionary

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.

Example 1:

Example 2:

Example 3:

Example 4:

Example 5:


  1. Create a mapping dictionary
  2. input your test example

3–4. get first element in s for stack dictionary

5–6. get second in s and top_element is stack element.

7–8 check mapping dictionary is same as top_element

9 return your result





Very hard to me and I need check reference….



Interesting in any computer science.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store