forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1933.java
30 lines (29 loc) · 901 Bytes
/
_1933.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.fishercoder.solutions;
public class _1933 {
public static class Solution1 {
public boolean isDecomposable(String s) {
int lengthTwoCount = 0;
for (int i = 0; i < s.length(); i++) {
int start = i;
char prev = s.charAt(start);
while (i < s.length() && s.charAt(i) == prev) {
i++;
}
if (i >= s.length()) {
i--;
}
if (s.charAt(i) != prev) {
i--;
}
if ((i - start + 1) % 3 == 2) {
lengthTwoCount++;
} else if ((i - start + 1) % 3 == 0) {
continue;
} else {
return false;
}
}
return lengthTwoCount == 1;
}
}
}