forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48c9b62
commit 800a37b
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
Two_Pointers/2461.Maximum-Sum-of-Distinct-Subarrays-With-Length-K/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
### 2461.Maximum-Sum-of-Distinct-Subarrays-With-Length-K | ||
|
||
非常普通的固定长度的滑窗。 | ||
|
||
用一个HashMap来记录每个number出现的次数。用count来表示滑窗内的distinct number的数量。count的变动依据如下: | ||
1. 当新加入一个数字时 | ||
```cpp | ||
Map[num]++; | ||
if (Map[num]==1) | ||
count++; | ||
``` | ||
2. 当移出一个数字时 | ||
```cpp | ||
Map[num]--; | ||
if (Map[num]==0) | ||
count--; | ||
``` |