页面顶部 Top
文件:  root - text - article - 2019 - 10 - daily-problem-validate-balanced-parentheses.txt
标签: 每日算法, 括号匹配, 面试, Python, daily problem, Validate Balanced Parentheses, algorithms, twitter interview question, python, | 英文 | 主页 | 类别: 计算机科学 | 214 次阅读, 17378 次搜索 | 161 个单词

定阅此目录的博客 | 浏览 | 博客存档
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))
标签: 每日算法, 括号匹配, 面试, Python, daily problem, Validate Balanced Parentheses, algorithms, twitter interview question, python, | 英文 | 主页 | 类别: 计算机科学 | 214 次阅读, 17378 次搜索 | 161 个单词 定阅此目录的博客

猜您喜欢...

  1. Algorithm Interview: Determine If Linked List is Palindrome
  2. Algorithm Interview Question: Symmetric k-ary Tree
  3. [Daily Problem] Angles of a Clock
  4. Sort a Partially Sorted List
  5. Daily Interview Problem: Count Number of Unival Subtrees
  6. Daily Interview Problem: Maximum Profit From Stocks
  7. New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
  8. Algorithm Interview: Lowest Common Ancestor of 2 Nodes in Binary Tree
  9. Algorithm Interview: String Compression
  10. CVE-2015-8874 - cPanel EasyApache Vulnerabilities

评论 (0)

    当前页暂时没有评论。


最后更新: October 30 2020 14:21:12 | RSS Subscription
牛排怎么做才好吃? | <meta name="机器人" content="索引, 跟踪">