Skip to content

Commit 9969d8e

Browse files
committed
docs: add algorithm description
1 parent 7d06b8c commit 9969d8e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/hard/sliding_window_maximum.rs

+14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ pub fn max_sliding_window(nums: Vec<i32>, k: i32) -> Vec<i32> {
2626
result
2727
}
2828

29+
/*
30+
Algorithm - Sliding Window
31+
32+
Time O(N)
33+
Space O(N)
34+
35+
Description:
36+
1. We use a window to store the index of the elements.
37+
2. We remove the first element if it is out of the window.
38+
3. We remove all elements smaller than the current one.
39+
4. We add the current element.
40+
5. We add the maximum to the result.
41+
*/
42+
2943
#[cfg(test)]
3044
mod tests {
3145
use super::*;

0 commit comments

Comments
 (0)