Skip to content

Commit 2ed2d8b

Browse files
committed
0763.划分字母区间.md Javascript
1 parent af5a95a commit 2ed2d8b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

problems/0763.划分字母区间.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,26 @@ class Solution:
128128

129129
Go:
130130

131-
131+
Javascript:
132+
```Javascript
133+
var partitionLabels = function(s) {
134+
let hash = {}
135+
for(let i = 0; i < s.length; i++) {
136+
hash[s[i]] = i
137+
}
138+
let result = []
139+
let left = 0
140+
let right = 0
141+
for(let i = 0; i < s.length; i++) {
142+
right = Math.max(right, hash[s[i]])
143+
if(right === i) {
144+
result.push(right - left + 1)
145+
left = i + 1
146+
}
147+
}
148+
return result
149+
};
150+
```
132151

133152

134153
-----------------------

0 commit comments

Comments
 (0)