bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 856. Score of Parentheses

856. Score of Parentheses

Leetcode Solutions

Count Cores Approach

  1. Initialize a variable balance to 0 and score to 0.
  2. Iterate through the string character by character.
  3. When you encounter '(', increment balance.
  4. When you encounter ')', check if the previous character was '('. If it was, add 1 << (balance - 1) to score.
  5. After adding to the score for a core, decrement balance.
  6. Continue this process until you have processed the entire string.
  7. Return the score.
UML Thumbnail

Stack Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...