To the Top
File:  root - text - article - 2019 - 10 - daily-problem-validate-balanced-parentheses.txt
Tags: 每日算法, 括号匹配, 面试, Python, daily problem, Validate Balanced Parentheses, algorithms, twitter interview question, python, | English | Home Page | Category: Computing | 215 Views, 17796 Search Bots | 161 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Uber:

Imagine you are building a compiler. Before running any code, the compiler must check that the parentheses in the program are balanced. Every opening bracket must have a corresponding closing bracket. We can approximate this using strings.

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
- Open brackets are closed by the same type of brackets.
- Open brackets are closed in the correct order.
- Note that an empty string is also considered valid.

Example:
Input: "((()))"
Output: True

Input: "[()]{}"
Output: True

Input: "({[)]"
Output: False


class Solution:
def isValid(self, s):
# Fill this in.

# Test Program
s = "()(){(())"
# should return False
print(Solution().isValid(s))

s = ""
# should return True
print(Solution().isValid(s))

s = "([{}])()"
# should return True
print(Solution().isValid(s))
Tags: 每日算法, 括号匹配, 面试, Python, daily problem, Validate Balanced Parentheses, algorithms, twitter interview question, python, | English | Home Page | Cateogry: Computing | 215 Views, 17796 Search Bots | 161 Words Subscribe to Feed Burner

Related Articles

  1. Number of Ways to Climb Stairs
  2. Algorithm Interview: Lowest Common Ancestor of 2 Nodes in Binary Tree
  3. Algorithm Interview: Longest Consecutive Sequence
  4. Daily Interview Question: Create a Simple Calculator
  5. Delphi Dynamic Array
  6. Daily Interview Problem: Largest BST in a Binary Tree
  7. Daily Interview Problem: Look and Say Sequence
  8. Progess made
  9. Algorithm Interview Question: Nth Fibonacci Number
  10. Find the non-duplicate number

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />