Skip to content

Commit 44e2079

Browse files
committed
add 763 ts solution
1 parent c67eae6 commit 44e2079

File tree

1 file changed

+21
-0
lines changed
  • Problems/19-Partition-Labels

1 file changed

+21
-0
lines changed

Problems/19-Partition-Labels/763.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function partitionLabels(s: string): number[] {
2+
3+
let map: Map<string,number> = new Map();
4+
let res: number[] = [];
5+
6+
for(let i = 0; i < s.length; i++) {
7+
map.set(s[i],i);
8+
}
9+
10+
let start = 0, end = 0;
11+
for(let i = 0; i < s.length; i++) {
12+
end = Math.max(map.get(s[i])!, end);
13+
if(i === end){
14+
end = i;
15+
res.push(end - start + 1);
16+
start = end+1;
17+
}
18+
}
19+
return res;
20+
21+
};

0 commit comments

Comments
 (0)