File: root - text - article - 2020 - 02 - fix-brackets.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 1014 Views, 23474 Search Bots | 99 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 1014 Views, 23474 Search Bots | 99 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Twitter:
Given a string with only ( and ), find the minimum number of characters to add or subtract to fix the string such that the brackets are balanced.
Example:
Input: '(()()'
Output: 1
Explanation:
The fixed string could either be ()() by deleting the first bracket, or (()()) by adding a bracket. These are not the only ways of fixing the string, there are many other ways by adding it in different positions!
Here's some code to start with:
def fix_brackets(s):
# Fill this in.
print fix_brackets('(()()')
# 1
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 1014 Views, 23474 Search Bots | 99 Words Given a string with only ( and ), find the minimum number of characters to add or subtract to fix the string such that the brackets are balanced.
Example:
Input: '(()()'
Output: 1
Explanation:
The fixed string could either be ()() by deleting the first bracket, or (()()) by adding a bracket. These are not the only ways of fixing the string, there are many other ways by adding it in different positions!
Here's some code to start with:
def fix_brackets(s):
# Fill this in.
print fix_brackets('(()()')
# 1
Related Articles
- Daily Interview Problem: Arithmetic Binary Tree
- CPU Utilization
- Consecutive Ones
- Daily Interview Problem: Look and Say Sequence
- Windows Scripting
- Daily Interview Problem: Reconstrunct Binary Tree from Preorder and Inorder Traversals
- YES!!
- Algorithm Interview: Lowest Common Ancestor of 2 Nodes in Binary Tree
- Daily Interview Problem: Sort Colors
- Daily Interview Question: Find Cycles in a Graph
©2006~2024 SteakOverCooked - 0.0088 Seconds(s) - 6145.333 KB/s - 43 Online Memory: 515.59 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !