Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6e731fc

Browse files
feat: add typescript solution to lc problem: No.0763.Partition Labels (doocs#583)
1 parent 8bf8ea2 commit 6e731fc

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

‎solution/0700-0799/0763.Partition Labels/README.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@
5353

5454
```
5555

56+
### **TypeScript**
57+
58+
```ts
59+
function partitionLabels(s: string): number[] {
60+
const n = s.length;
61+
let last = new Array(128);
62+
for (let i = 0; i < n; i++) {
63+
last[s.charCodeAt(i)] = i;
64+
}
65+
let ans = [];
66+
let left = 0, right = 0;
67+
for (let i = 0; i < n; i++) {
68+
right = Math.max(right, last[s.charCodeAt(i)]);
69+
if (i == right) {
70+
ans.push(right - left + 1);
71+
left = right + 1;
72+
}
73+
}
74+
return ans;
75+
};
76+
```
77+
5678
### **...**
5779

5880
```

‎solution/0700-0799/0763.Partition Labels/README_EN.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ A partition like &quot;ababcbacadefegde&quot;, &quot;hijhklij&quot; is incorrect
4747

4848
```
4949

50+
### **TypeScript**
51+
52+
```ts
53+
function partitionLabels(s: string): number[] {
54+
const n = s.length;
55+
let last = new Array(128);
56+
for (let i = 0; i < n; i++) {
57+
last[s.charCodeAt(i)] = i;
58+
}
59+
let ans = [];
60+
let left = 0, right = 0;
61+
for (let i = 0; i < n; i++) {
62+
right = Math.max(right, last[s.charCodeAt(i)]);
63+
if (i == right) {
64+
ans.push(right - left + 1);
65+
left = right + 1;
66+
}
67+
}
68+
return ans;
69+
};
70+
```
71+
5072
### **...**
5173

5274
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function partitionLabels(s: string): number[] {
2+
const n = s.length;
3+
let last = new Array(128);
4+
for (let i = 0; i < n; i++) {
5+
last[s.charCodeAt(i)] = i;
6+
}
7+
let ans = [];
8+
let left = 0, right = 0;
9+
for (let i = 0; i < n; i++) {
10+
right = Math.max(right, last[s.charCodeAt(i)]);
11+
if (i == right) {
12+
ans.push(right - left + 1);
13+
left = right + 1;
14+
}
15+
}
16+
return ans;
17+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /