forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1525.java
36 lines (34 loc) · 1.05 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
package com.fishercoder.solutions;
public class _1525 {
public static class Solution1 {
public int numSplits(String s) {
int goodSplits = 0;
int[] left = new int[26];
int[] right = new int[26];
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
right[c - 'a']++;
}
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
left[c - 'a']++;
int distinctCharOnTheLeft = getDistinct(left);
right[c - 'a']--;
int distinctCharOnTheRight = getDistinct(right);
if (distinctCharOnTheLeft == distinctCharOnTheRight) {
goodSplits++;
}
}
return goodSplits;
}
private int getDistinct(int[] count) {
int c = 0;
for (int i : count) {
if (i != 0) {
c++;
}
}
return c;
}
}
}