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 | 1038 Views, 24627 Search Bots | 99 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 1038 Views, 24627 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 | 1038 Views, 24627 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: Min Range Needed to Sort
- Daily Interview Problem: Full Binary Tree
- Sort a Partially Sorted List
- Windows Scripting
- Daily Interview Problem: Queue Using Two Stacks
- Daily Interview Problem: Minimum Removals for Valid Parenthesis
- Reverse a Directed Graph
- Daily Interview Problem: Decode String
- Algorithm Interview Question: Find the Single Element in an Array of Duplicates
- CPU Utilization
©2006~2024 SteakOverCooked - 0.00747 Seconds(s) - 2567.726 KB/s - 12 Online Memory: 492.38 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 !