1
class Solution {
2
public List<Integer> partitionLabels(String s) {
3

4
List<Integer> lr = new ArrayList<>();
5

6
HashMap<Character, Boolean> mp = new HashMap<>();
7

8
int count = 0;
9

10
for (int i = 0; i < s.length(); i++) {
11

12
if (!mp.containsKey(s.charAt(i)) && s.lastIndexOf(Character.toString(s.charAt(i))) != i) {
13
mp.put(s.charAt(i), true);
14
} else if (mp.containsKey(s.charAt(i))
15
&& s.lastIndexOf(Character.toString(s.charAt(i))) == i) {
16

17
mp.remove(s.charAt(i));
18
}
19

20
if (mp.isEmpty()) {
21
lr.add(count + 1);
22
count = 0;
23
} else {
24
count++;
25
}
26
}
27

28
return lr;
29
}
30
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0