- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1525.java
36 lines (34 loc) · 1.06 KB
/
_1525.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
31
32
33
34
35
36
packagecom.fishercoder.solutions.secondthousand;
publicclass_1525 {
publicstaticclassSolution1 {
publicintnumSplits(Strings) {
intgoodSplits = 0;
int[] left = newint[26];
int[] right = newint[26];
for (inti = 0; i < s.length(); i++) {
charc = s.charAt(i);
right[c - 'a']++;
}
for (inti = 0; i < s.length(); i++) {
charc = s.charAt(i);
left[c - 'a']++;
intdistinctCharOnTheLeft = getDistinct(left);
right[c - 'a']--;
intdistinctCharOnTheRight = getDistinct(right);
if (distinctCharOnTheLeft == distinctCharOnTheRight) {
goodSplits++;
}
}
returngoodSplits;
}
privateintgetDistinct(int[] count) {
intc = 0;
for (inti : count) {
if (i != 0) {
c++;
}
}
returnc;
}
}
}