Skip to content

Commit 264bbb4

Browse files
authored
Create Check if String Is Decomposable Into Value-Equal Substrings.java
1 parent 5630843 commit 264bbb4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public boolean isDecomposable(String s) {
3+
boolean sizeTwoFound = false;
4+
int idx = 0;
5+
while (idx < s.length()) {
6+
char c = s.charAt(idx);
7+
int tempIdx = idx;
8+
while (tempIdx < s.length() && s.charAt(tempIdx) == c && tempIdx - idx < 3) {
9+
tempIdx++;
10+
}
11+
int occurrences = tempIdx - idx;
12+
if (occurrences < 2) {
13+
return false;
14+
}
15+
if (occurrences == 2) {
16+
if (sizeTwoFound) {
17+
return false;
18+
}
19+
sizeTwoFound = true;
20+
}
21+
idx = tempIdx;
22+
}
23+
return sizeTwoFound;
24+
}
25+
}

0 commit comments

Comments
 (0)