python, CPP Sliding window與組合公式解Leetcode 2962. Count Subarrays Where Max Element Appears at Least K Times
兩種截然不同的方式解題,一種是用組合公式,算左右端點的可能,乘法律、加法律,數學解法先解出。
另一種是sliding window就用這幾天解題的那種pattern一套就靈,快速簡潔。
------
There are two completely different ways to solve the problem. One is to use combination formulas to calculate the number of possiblities for left right ends using multiplicative principle and additive principle. The mathematical solution is solved first.
The other is the sliding window, which uses the same pattern that has been used to solve problems these days. It is quick and concise.
[codes on Leetcode]https://leetcode.com/problems/count-subarrays-where-max-element-appears-at-least-k-times/solutions/4939830/sliding-window-vs-combinatorical-formula-59ms-beats-100/
[sliding window/2 pointer play list]https://www.youtube.com/watch?v=pi1XpQU_Yxo&list=PLYRlUBnWnd5KrCfs7qCFb-Bvn7dvnakFy
沒有留言:
張貼留言