We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 89d44ea commit 0dccaf5Copy full SHA for 0dccaf5
763_PartitionLabels.swift
@@ -0,0 +1,27 @@
1
+extension Character {
2
+ var ascii: Int {
3
+ return Int(self.unicodeScalars.first!.value)
4
+ }
5
+}
6
+class Solution {
7
+ func partitionLabels(_ S: String) -> [Int] {
8
+ // if S.isEmpty {
9
+ // return [0]
10
+ // }
11
+ var map = Array(repeating: -1, count: 26+97)
12
+ for (i, c) in S.enumerated() {
13
+ map[c.ascii] = i
14
15
+ var result = [Int]()
16
+ var start = 0, end = 0
17
18
+ let right = map[c.ascii]
19
+ end = max(end, right)
20
+ if i == end {
21
+ result.append(end-start+1)
22
+ start = end + 1
23
24
25
+ return result
26
27
0 commit comments