8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c80bca1 commit 79b2fd0Copy full SHA for 79b2fd0
109. Longest Substring Without Repeating Characters/README.md
@@ -0,0 +1,31 @@
1
+设 substr 的起点为 start(s), 终点为 last(l). 每一次迭代,记录一张索引表。
2
+
3
+ abcabcbb
4
+ ^ ^
5
+ s l
6
7
+|char|pos|
8
+|:--:|:-:|
9
+| a | 0 |
10
+| b | 1 |
11
+| c | 2 |
12
13
+上图所示,last 指向 `a`, 查询当前表可知,`a` 的位置记录在案,且 `pos >= start`. 故此刻诞生一个 substr. 长度为 `last - start`. s 更新位置为 `pos + 1`.
14
15
+有:
16
17
+```cpp
18
+auto found = cache.find(s[last]);
19
+if (found != cache.end() && found->second >= start) {
20
+ ret = max(ret, last - start);
21
+ start = found->second + 1;
22
+}
23
+cache[s[last]] = last;
24
+```
25
26
+注意最终还需要比较一次,返回 `max(ret, s.size() - start)`
27
28
29
30
31
0 commit comments