AI代码解释 classSolution(object):defscoreOfParentheses(self,S):ans=bal=0fori,xinenumerate(S):ifx=='(':bal+=1else:bal-=1ifS[i-1]=='(':ans+=1<<balreturnans 参考链接:https://leetcode-cn.com/problems/score-of-parentheses/solution/gua-hao-de-fen-shu-by-leetcode/...
ans+= 1 <<balreturnans 参考链接:https://leetcode-cn.com/problems/score-of-parentheses/solution/gua-hao-de-fen-shu-by-leetcode/
代码(Python3) class Solution: def scoreOfParentheses(self, s: str) -> int: # score 统计所有括号的分数和 score: int = 0 # 维护每一个括号当前的深度 depth: int = 0 # 带下标遍历每一个括号 for (i, ch) in enumerate(s): if ch == '(': # 如果当前是左括号,则深度加 1 depth +=...
解法一: classSolution{public:intscoreOfParentheses(stringS){intres =0, n = S.size();for(inti =0; i < n; ++i) {if(S[i] ==')')continue;intpos = i +1, cnt =1;while(cnt !=0) { (S[pos++] =='(') ? ++cnt : --cnt; }intcur = scoreOfParentheses(S.substr(i +1, pos...
https://github.com/grandyang/leetcode/issues/856 类似题目: Valid Parentheses 参考资料: https://leetcode.com/problems/score-of-parentheses/ https://leetcode.com/problems/score-of-parentheses/discuss/141777/C%2B%2BJavaPython-O(1)-Space [LeetCode All in One 题目讲解汇总(持续更新中...)](...
支持Java、C++、JavaScript、Python2、Python3、Go 六种热门编程语言,让广大的程序员可以自由选择自己擅长的语言; LintCode上每一道题都设有中文和英文描述,同时满足国内及海外用户,可以根据自己的喜好自由设置。 LintCode 使用指南 1、直接刷题 进入LintCode 主页,在顶部“算法”菜单中选择“全部题目”,题库已经按...
class Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype: int 返回值为最大盛水量 """ head = 0 tail = len(height) - 1 max_water = 0 while head < tail: max_water = max(max_water, min(height[head], height[tail]) * (tail - head)) ...
856 括号的分数 - Score of Parentheses C# C++ Java Python Medium 855 考场就座 - Exam Room C# C++ Java Python Medium 854 相似度为 K 的字符串 - K-Similar Strings C# C++ Java Python Hard 853 车队- Car Fleet C# C++ Java Python Medium 852 山脉数组的峰顶索引 - Peak Index in a Mountain ...
856 + ```java 857 + // Welcome to create a PR to complete the code of this language, thanks! 858 + ``` 859 + 589 860 Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [LeetCodePython.com](https://leetcodepython.com): Dare to ...
classSolution{publicbooleanisValidSerialization(String preorder){int n=preorder.length();int i=0;Deque<Integer>stack=newLinkedList<Integer>();stack.push(1);while(i<n){if(stack.isEmpty()){returnfalse;}if(preorder.charAt(i)==','){i++;}elseif(preorder.charAt(i)=='#'){int top=stack...