Skip to content

Files

Latest commit

c3a8653 · May 18, 2020

History

History

02-04 Balanced Parentheses Check

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
May 18, 2020
May 18, 2020
May 18, 2020

Balanced Parentheses Check

Problem

Given a string of opening and closing parentheses, check whether it’s balanced. We have 3 types of parentheses: round brackets: (), square brackets: [], and curly brackets: {}. Assume that the string doesn’t contain any other character than these, no spaces words or numbers. As a reminder, balanced parentheses require every opening parenthesis to be closed in the reverse order opened. For example ‘([])’ is balanced but ‘([)]’ is not.

You can assume the input string has no spaces.

Leetcode: https://leetcode.com/problems/valid-parentheses/

Code

Create your solution in the form:

def balance_check(s):
    pass

Examples

>>> balance_check('[]')
True
>>> balance_check('[](){([[[]]])}')
True
>>> balance_check('()(){]}')
False