mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
0763.划分字母区间.md Javascript
This commit is contained in:
@ -128,7 +128,26 @@ class Solution:
|
||||
|
||||
Go:
|
||||
|
||||
|
||||
Javascript:
|
||||
```Javascript
|
||||
var partitionLabels = function(s) {
|
||||
let hash = {}
|
||||
for(let i = 0; i < s.length; i++) {
|
||||
hash[s[i]] = i
|
||||
}
|
||||
let result = []
|
||||
let left = 0
|
||||
let right = 0
|
||||
for(let i = 0; i < s.length; i++) {
|
||||
right = Math.max(right, hash[s[i]])
|
||||
if(right === i) {
|
||||
result.push(right - left + 1)
|
||||
left = i + 1
|
||||
}
|
||||
}
|
||||
return result
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
-----------------------
|
||||
|
Reference in New Issue
Block a user