sliding window:滑动窗口。一种常见的算法思路:在数组、字符串或时间序列上维护一个“窗口”(连续区间),通过窗口的移动与增减元素来高效计算满足条件的子区间/子串(如最长/最短、计数、和、频率等)。常用于“双指针”与“流式数据”场景。(在网络通信中也可指“滑动窗口协议”,属于另一常见含义。)
/ˈslaɪdɪŋ ˈwɪndoʊ/
We used a sliding window to find the longest substring without repeating characters.
我们用滑动窗口来找出不含重复字符的最长子串。
By maintaining counts inside the sliding window and moving its boundaries, the algorithm runs in linear time instead of quadratic time.
通过在滑动窗口内维护计数并移动左右边界,该算法从平方级复杂度降为线性时间。
sliding 来自动词 slide(滑动、滑行),window 原义为“窗/窗口”。在算法语境中,“window(窗口)”比喻“当前正在观察或处理的一段范围”,而“sliding(滑动)”强调这段范围会沿着数据逐步移动,因此形成“sliding window(滑动窗口)”这一形象说法。