Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int max(int a, int b){
- return a > b ? a : b;
- }
- int scoreOfParentheses(string S) {
- stack<int> s;
- int res = 0;
- for(char c: S){
- if(c == '('){
- s.push(res);
- res = 0;
- }
- else{
- res = s.top() + max(res*2, 1);
- s.pop();
- }
- }
- return res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement