8000 add 2696 · shaovoon/Leetcode@3b90fd3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b90fd3

Browse files
add 2696
1 parent 588232b commit 3b90fd3

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
11+
| 2696 |[Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2696.java) | | Easy |
1112
| 2670 |[Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2670.java) | | Easy |
1213
| 2596 |[Check Knight Tour Configuration](https://leetcode.com/problems/check-knight-tour-configuration/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2596.java) | [:tv:](https://youtu.be/OBht8NT_09c) | Medium |
1314
| 2595 |[Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2595.java) | | Easy |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Deque;
4+
import java.util.LinkedList;
5+
6+
public class _2696 {
7+
public static class Solution1 {
8+
public int minLength(String s) {
9+
Deque<Character> stack = new LinkedList<>();
10+
for (int i = 0; i < s.length(); i++) {
11+
if (stack.isEmpty()) {
12+
stack.addLast(s.charAt(i));
13+
} else if (s.charAt(i) == 'B' && stack.peekLast() == 'A') {
14+
stack.pollLast();
15+
} else if (s.charAt(i) == 'D' && stack.peekLast() == 'C') {
16+
stack.pollLast();
17+
} else {
18+
stack.addLast(s.charAt(i));
19+
}
20+< 8000 /span>
}
21+
return stack.size();
22+
}
23+
}
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._2696;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2696Test {
10+
private static _2696.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _2696.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(2, solution1.minLength("ABFCACDB"));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)
0