Skip to content

Commit bd7feb8

Browse files
add skeleton for 856
1 parent 9ddc344 commit bd7feb8

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ _If you like this project, please leave me a star._ ★
177177
|867|[Transpose Matrix](https://leetcode.com/problems/transpose-matrix/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_867.java) | |Easy|
178178
|860|[Lemonade Change](https://leetcode.com/problems/lemonade-change/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_860.java) | |Easy|
179179
|859|[Buddy Strings](https://leetcode.com/problems/buddy-strings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_859.java) | |Easy|
180+
|856|[Score of Parentheses](https://leetcode.com/problems/score-of-parentheses/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_856.java) | |Medium| Stack, String
180181
|852|[Peak Index in a Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_852.java) | |Easy|
181182
|849|[Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_849.java) | |Easy|
182183
|844|[Backspace String Compare](https://leetcode.com/problems/backspace-string-compare/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_844.java) | |Easy|
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Stack;
4+
5+
/**
6+
* 856. Score of Parentheses
7+
*
8+
* Given a balanced parentheses string S, compute the score of the string based on the following rule:
9+
* () has score 1
10+
* AB has score A + B, where A and B are balanced parentheses strings.
11+
* (A) has score 2 * A, where A is a balanced parentheses string.
12+
*
13+
* Example 1:
14+
* Input: "()"
15+
* Output: 1
16+
*
17+
* Example 2:
18+
* Input: "(())"
19+
* Output: 2
20+
*
21+
* Example 3:
22+
* Input: "()()"
23+
* Output: 2
24+
*
25+
* Example 4:
26+
* Input: "(()(()))"
27+
* Output: 6
28+
*
29+
* Note:
30+
* S is a balanced parentheses string, containing only ( and ).
31+
* 2 <= S.length <= 50
32+
* */
33+
public class _856 {
34+
public static class Solution1 {
35+
public int scoreOfParentheses(String S) {
36+
return -1;
37+
}
38+
}
39+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._856;
4+
import org.junit.BeforeClass;
5+
import org.junit.Ignore;
6+
import org.junit.Test;
7+
8+
import static org.junit.Assert.assertEquals;
9+
10+
@Ignore
11+
public class _856Test {
12+
private static _856.Solution1 solution1;
13+
14+
@BeforeClass
15+
public static void setup() {
16+
solution1 = new _856.Solution1();
17+
}
18+
19+
@Test
20+
public void test1() {
21+
assertEquals(1, solution1.scoreOfParentheses("()"));
22+
}
23+
24+
@Test
25+
public void test2() {
26+
assertEquals(2, solution1.scoreOfParentheses("(())"));
27+
}
28+
29+
@Test
30+
public void test3() {
31+
assertEquals(2, solution1.scoreOfParentheses("()()"));
32+
}
33+
34+
@Test
35+
public void test4() {
36+
assertEquals(6, solution1.scoreOfParentheses("(()(()))"));
37+
}
38+
39+
@Test
40+
public void test5() {
41+
assertEquals(16, solution1.scoreOfParentheses("((((()))))"));
42+
}
43+
44+
@Test
45+
public void test6() {
46+
assertEquals(8, solution1.scoreOfParentheses("(((())))"));
47+
}
48+
49+
@Test
50+
public void test7() {
51+
assertEquals(8, solution1.scoreOfParentheses("((())(()))"));
52+
}
53+
54+
@Test
55+
public void test8() {
56+
assertEquals(8, solution1.scoreOfParentheses("(()()(()))"));
57+
}
58+
59+
@Test
60+
public void test9() {
61+
assertEquals(12, solution1.scoreOfParentheses("(()()(()()))"));
62+
}
63+
64+
}

0 commit comments

Comments
 (0)