We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 284ad4f commit a9cf145Copy full SHA for a9cf145
src/main/java/com/fishercoder/solutions/_856.java
@@ -11,13 +11,13 @@ public int scoreOfParentheses(String S) {
11
Stack<Integer> stack = new Stack<>();
12
for (int i = 0; i < S.length(); i++) {
13
if (S.charAt(i) == '(') {
14
- stack.push(-1);
+ stack.push(-1);//we use -1 to indicate this is a left paren '('
15
} else {
16
int curr = 0;
17
while (stack.peek() != -1) {
18
curr += stack.pop();
19
}
20
- stack.pop();
+ stack.pop();//this is to push the '(' off of the stack
21
stack.push(curr == 0 ? 1 : curr * 2);
22
23
0 commit comments