We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 49f6123 commit d00bf46Copy full SHA for d00bf46
JAVA/763_Partition_Level.java
@@ -0,0 +1,25 @@
1
+// Problem Number: 763
2
+
3
+// Partition Level
4
5
+class Solution {
6
+ public List<Integer> partitionLabels(String s) {
7
+ List<Integer> ans = new ArrayList<>();
8
+ int[] rightmost = new int[26];
9
10
+ for (int i = 0; i < s.length(); ++i)
11
+ rightmost[s.charAt(i) - 'a'] = i;
12
13
+ int l = 0; // the leftmost index of the current running string
14
+ int r = 0; // the rightmost index of the current running string
15
16
+ for (int i = 0; i < s.length(); ++i) {
17
+ r = Math.max(r, rightmost[s.charAt(i) - 'a']);
18
+ if (r == i) {
19
+ ans.add(i - l + 1);
20
+ l = i + 1;
21
+ }
22
23
+ return ans;
24
25
+}
0 commit comments