Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita9cf145

Browse files
refactor 856
1 parent284ad4f commita9cf145

File tree

1 file changed

+2
-2
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+2
-2
lines changed

‎src/main/java/com/fishercoder/solutions/_856.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ public int scoreOfParentheses(String S) {
1111
Stack<Integer>stack =newStack<>();
1212
for (inti =0;i <S.length();i++) {
1313
if (S.charAt(i) =='(') {
14-
stack.push(-1);
14+
stack.push(-1);//we use -1 to indicate this is a left paren '('
1515
}else {
1616
intcurr =0;
1717
while (stack.peek() != -1) {
1818
curr +=stack.pop();
1919
}
20-
stack.pop();
20+
stack.pop();//this is to push the '(' off of the stack
2121
stack.push(curr ==0 ?1 :curr *2);
2222
}
2323
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp