package leetcode func scoreOfParentheses(S string) int { res, stack, top, temp := 0, []int{}, -1, 0 for _, s := range S { if s == '(' { stack = append(stack, -1) top++ } else { temp = 0 for stack[top] != -1 { t
Given a balanced parentheses string s, return the score of the string. The score of a balanced parentheses string is based on the following rule: "()" has score 1. AB has score A + B, where A and B are balanced parentheses strings. (A) has score 2 * A, where A is a balanced ...
Given a balanced parentheses string `S`, compute the score of the string based on the following rule: ()has score 1 ABhas scoreA + B, where A and B are balanced parentheses strings. (A)has score2 * A, where A is a balanced parentheses string. Example 1: Input:"()"Output:1 Exampl...
题目链接: Score of Parentheses : leetcode.com/problems/s 括号的分数: leetcode-cn.com/problem LeetCode 日更第 63 天,感谢阅读至此的你 欢迎点赞、收藏鼓励支持小满 编辑于 2022-03-20 10:27 力扣(LeetCode) Python Go 语言 赞同添加评论 分享喜欢收藏申请转载 ...
leetcode 856. 括号的分数(Score of Parentheses) 题目描述: 给定一个平衡括号字符串 S,按下述规则计算该字符串的分数: () 得 1 分。 AB 得 A + B 分,其中 A 和 B 是平衡括号字符串。 (A) 得 2 * A 分,其中 A 是平衡括号字符串。 示例1:...
LeetCode 32. Longest Valid Parentheses Given astringcontaining just the characters '(' and ')', find the lengthofthe longest valid (well-formed)parenthesessubstring. Example 1: Example 2: 解法一:用栈stack 解法二:动态规划DP 【LeetCode】856. Score of Parentheses 解题报告(Python & C++) ...
Leetcode 856. Score of Parentheses 括号得分(栈) 题目描述 字符串S包含平衡的括号(即左右必定匹配),使用下面的规则计算得分 + 得1分 + 得A+B的分,比如 得
[LeetCode] 856. Score of Parentheses 括号的分数Given a balanced parentheses string `S`, compute the score of the string based on the following rule: () has score 1 AB has score A + B, where A and B are balanced parentheses strings. (A) has score 2 * A, where A is a balanced...
1111-Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings 1118-Number-of-Days-in-a-Month 1119-Remove-Vowels-from-a-String 1120-Maximum-Average-Subtree .gitignore qrcode.png readme.md Breadcrumbs Play-Leetcode /0856-Score-of-Parentheses / cpp-0856/ Directory actions ...
class Solution { public: int scoreOfParentheses(string S) { // (:-2, ):-1 stack<int> st; for (int i = 0; i < S.size(); i++) { char c = S[i]; if (c == '(') st.push(-2); else if (c == ')') { int sum = 0; int time = 0; while (!st.empty()) { ...