mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-21 04:56:46 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个括号字符串 <code>s</code> ,它只包含字符 <code>'('</code> 和 <code>')'</code> 。一个括号字符串被称为平衡的当它满足:</p>\n\n<ul>\n\t<li>任何左括号 <code>'('</code> 必须对应两个连续的右括号 <code>'))'</code> 。</li>\n\t<li>左括号 <code>'('</code> 必须在对应的连续两个右括号 <code>'))'</code> 之前。</li>\n</ul>\n\n<p>比方说 <code>"())"</code>, <code>"())(())))"</code> 和 <code>"(())())))"</code> 都是平衡的, <code>")()"</code>, <code>"()))"</code> 和 <code>"(()))"</code> 都是不平衡的。</p>\n\n<p>你可以在任意位置插入字符 '(' 和 ')' 使字符串平衡。</p>\n\n<p>请你返回让 <code>s</code> 平衡的最少插入次数。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>s = "(()))"\n<strong>输出:</strong>1\n<strong>解释:</strong>第二个左括号有与之匹配的两个右括号,但是第一个左括号只有一个右括号。我们需要在字符串结尾额外增加一个 ')' 使字符串变成平衡字符串 "(())))" 。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>s = "())"\n<strong>输出:</strong>0\n<strong>解释:</strong>字符串已经平衡了。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><strong>输入:</strong>s = "))())("\n<strong>输出:</strong>3\n<strong>解释:</strong>添加 '(' 去匹配最开头的 '))' ,然后添加 '))' 去匹配最后一个 '(' 。\n</pre>\n\n<p><strong>示例 4:</strong></p>\n\n<pre><strong>输入:</strong>s = "(((((("\n<strong>输出:</strong>12\n<strong>解释:</strong>添加 12 个 ')' 得到平衡字符串。\n</pre>\n\n<p><strong>示例 5:</strong></p>\n\n<pre><strong>输入:</strong>s = ")))))))"\n<strong>输出:</strong>5\n<strong>解释:</strong>在字符串开头添加 4 个 '(' 并在结尾添加 1 个 ')' ,字符串变成平衡字符串 "(((())))))))" 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 10^5</code></li>\n\t<li><code>s</code> 只包含 <code>'('</code> 和 <code>')'</code> 。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 39,
|
||||
"likes": 41,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -149,7 +149,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"9.8K\", \"totalSubmission\": \"20.3K\", \"totalAcceptedRaw\": 9751, \"totalSubmissionRaw\": 20320, \"acRate\": \"48.0%\"}",
|
||||
"stats": "{\"totalAccepted\": \"10.6K\", \"totalSubmission\": \"22K\", \"totalAcceptedRaw\": 10589, \"totalSubmissionRaw\": 21992, \"acRate\": \"48.1%\"}",
|
||||
"hints": [
|
||||
"Use a stack to keep opening brackets. If you face single closing ')' add 1 to the answer and consider it as '))'.",
|
||||
"If you have '))' with empty stack, add 1 to the answer, If after finishing you have x opening remaining in the stack, add 2x to the answer."
|
||||
|
Reference in New Issue
Block a user