File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
8
8
9
9
| # | Title | Solutions | Video | Difficulty | Tag
10
10
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
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 |
11
12
| 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 |
12
13
| 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 |
13
14
| 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 |
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments