cbvirtua 1.0.82 → 1.0.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
function longestRepeating(s: string, queryCharacters: string, queryIndices: number[]): number[] {
|
|
2
|
+
const n = s.length
|
|
3
|
+
const q = queryIndices.length
|
|
4
|
+
const res = Array(q).fill(1)
|
|
5
|
+
|
|
6
|
+
const odt = new ODT(n, -1) // !珂朵莉树维护区间字符类型
|
|
7
|
+
s.split('').forEach((c, i) => {
|
|
8
|
+
odt.set(i, i + 1, c.charCodeAt(0) - 97)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const lens = new SortedList<number>() // !SortedList维护每个连续段的长度
|
|
12
|
+
odt.enumerateAll((start, end, value) => {
|
|
13
|
+
if (value !== -1) {
|
|
14
|
+
lens.add(end - start)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < q; i++) {
|
|
19
|
+
const target = queryCharacters.charCodeAt(i) - 97
|
|
20
|
+
const pos = queryIndices[i]
|
|
21
|
+
|
|
22
|
+
// !每次更新最多影响左中右三段区间
|
|
23
|
+
// !先删除这三段区间的长度,修改后,再添加这三段区间的长度
|
|
24
|
+
// 这种做法无需分类讨论
|
|
25
|
+
const [start, end] = odt.get(pos)!
|
|
26
|
+
const leftSeg = odt.get(start - 1)
|
|
27
|
+
const rightSeg = odt.get(end)
|
|
28
|
+
const first = leftSeg ? leftSeg[0] : 0
|
|
29
|
+
const last = rightSeg ? rightSeg[1] : n
|
|
30
|
+
odt.enumerateRange(first, last, (start, end) => {
|
|
31
|
+
lens.discard(end - start)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
odt.set(pos, pos + 1, target)
|
|
35
|
+
|
|
36
|
+
odt.enumerateRange(first, last, (start, end) => {
|
|
37
|
+
lens.add(end - start)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
res[i] = lens.max()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return res
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
作者:草莓奶昔🍓
|
|
47
|
+
链接:https://leetcode.cn/problems/longest-substring-of-one-repeating-character/solutions/2287639/typescript-ke-duo-li-shu-by-981377660lmt-n77n/
|
|
48
|
+
来源:力扣(LeetCode)
|
|
49
|
+
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
|