圆形图像改成方形,微调刷新按钮样式,优化代码高亮,更改代码块样式和复制按钮
代码高亮和复制:
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
class Solution {
public:
int findShortestSubArray(vector<int>& nums) {
unordered_map<int, int> count, first, last;
for (int i = 0; i < nums.size(); i++) {
int x = nums[i];
count[x]++;
if (!first.count(x)) first[x] = i;
last[x] = i;
}
int degree = 0;
for (auto &p : count) degree = max(degree, p.second);
int res = nums.size();
for (auto &p : count) {
if (p.second == degree) {
res = min(res, last[p.first] - first[p.first] + 1);
}
}
return res;
}
};
int main() {
Solution s;
vector<int> nums = {1,2,2,3,1};
cout << s.findShortestSubArray(nums) << endl; // 输出 2
return 0;
}