Skip to content

Commit 3fa84e1

Browse files
authored
Create Solution.java
1 parent 57de0e8 commit 3fa84e1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int scoreOfParentheses(String S) {
3+
int res = 0;
4+
for (int i = 0, d = 0; i < S.length(); ++i) {
5+
if (S.charAt(i) == '(') {
6+
++d;
7+
} else {
8+
--d;
9+
if (S.charAt(i - 1) == '(') {
10+
res += 1 << d;
11+
}
12+
}
13+
}
14+
return res;
15+
}
16+
}

0 commit comments

Comments
 (0)