Skip to content

Commit 43e2da8

Browse files
add 1933
1 parent 3d40976 commit 43e2da8

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ _If you like this project, please leave me a star._ ★
5151
|1941|[Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1941.java) ||Easy||
5252
|1936|[Add Minimum Number of Rungs](https://leetcode.com/problems/add-minimum-number-of-rungs/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1936.java) ||Medium||
5353
|1935|[Maximum Number of Words You Can Type](https://leetcode.com/problems/maximum-number-of-words-you-can-type/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1935.java) ||Easy|String|
54+
|1933|[Check if String Is Decomposable Into Value-Equal Substrings](https://leetcode.com/problems/check-if-string-is-decomposable-into-value-equal-substrings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1933.java) ||Easy|String|
5455
|1929|[Concatenation of Array](https://leetcode.com/problems/concatenation-of-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1929.java) ||Easy||
5556
|1926|[Nearest Exit from Entrance in Maze](https://leetcode.com/problems/nearest-exit-from-entrance-in-maze/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1926.java) ||Medium|DP, DFS, BFS|
5657
|1925|[Count Square Sum Triples](https://leetcode.com/problems/count-square-sum-triples/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1925.java) ||Easy|Array, Greedy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1933 {
4+
public static class Solution1 {
5+
public boolean isDecomposable(String s) {
6+
int lengthTwoCount = 0;
7+
for (int i = 0; i < s.length(); i++) {
8+
int start = i;
9+
char prev = s.charAt(start);
10+
while (i < s.length() && s.charAt(i) == prev) {
11+
i++;
12+
}
13+
if (i >= s.length()) {
14+
i--;
15+
}
16+
if (s.charAt(i) != prev) {
17+
i--;
18+
}
19+
if ((i - start + 1) % 3 == 2) {
20+
lengthTwoCount++;
21+
} else if ((i - start + 1) % 3 == 0) {
22+
continue;
23+
} else {
24+
return false;
25+
}
26+
}
27+
return lengthTwoCount == 1;
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1933;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1933Test {
10+
private static _1933.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1933.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(false, solution1.isDecomposable("000111000"));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(true, solution1.isDecomposable("00011111222"));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(false, solution1.isDecomposable("011100022233"));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)