3740. Minimum Distance Between Three Equal Elements I
Algorithm Steps
- Use
map<int, vector<int>>to record all the indices of each element - For each index array
p- Enumerate the length
>= 3 - Calculate
(p[i] - p[i-2]) * 2
- Enumerate the length
- Take the minimum value
Complexity Analysis
Time complexity: O(n)
Space complexity: O(n)
Cpp Code
|
|
Python Code
|
|
Go Code
|
|
JavaScript Code
|
|