Skip to content

Commit 52f485f

Browse files
authored
Update score-of-parentheses.cpp
1 parent 3bf782e commit 52f485f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

C++/score-of-parentheses.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ class Solution {
66
int scoreOfParentheses(string S) {
77
int result = 0, depth = 0;
88
for (int i = 0; i < S.length(); ++i) {
9-
(S[i] == '(') ? ++depth : --depth;
10-
if (S[i] == '(' && S[i + 1] == ')') {
11-
result += 1 << (depth - 1);
9+
if (S[i] == '(') {
10+
++depth;
11+
} else {
12+
--depth;
13+
if (S[i - 1] == '(') {
14+
result += 1 << depth;
15+
}
1216
}
1317
}
1418
return result;

0 commit comments

Comments
 (0)