Skip to content

Commit b11b46e

Browse files
committed
Create 0763-partition-labels.swift
1 parent a6b8103 commit b11b46e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

swift/0763-partition-labels.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
func partitionLabels(_ s: String) -> [Int] {
3+
var hashmap = [Character: Int]()
4+
for (i, c) in s.enumerated() {
5+
hashmap[c] = i
6+
}
7+
8+
var res = [Int]()
9+
var size = 0
10+
var end = 0
11+
for (i, c) in s.enumerated() {
12+
end = max(end, hashmap[c] ?? 0)
13+
size += 1
14+
if i == end {
15+
res.append(size)
16+
size = 0
17+
}
18+
}
19+
20+
return res
21+
}
22+
}

0 commit comments

Comments
 (0)