0
Leetcode Problem 856. Score of Parentheses
856. Score of Parentheses
AI Mock Interview
Leetcode Solutions
Count Cores Approach
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize a variable
balance
to 0 and
score
to 0.
Iterate through the string character by character.
When you encounter '(', increment
balance
.
When you encounter ')', check if the previous character was '('. If it was, add
1 << (balance - 1)
to
score
.
After adding to the score for a core, decrement
balance
.
Continue this process until you have processed the entire string.
Return the
score
.
Stack Approach
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...