题解 | #滑动窗口的最大值#
滑动窗口的最大值
http://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
a ! 没见过这么烂的代码
class Solution {
public:
vector<int> maxInWindows(const vector<int>& v, int size)
{
vector<int> vans;
for(int i = 0; i < v.size()-(size-1); i++)
{
int j = size, iMax = v[i];
while(j > 1) {
j--;
iMax = max(iMax, v[i+j]);
}
vans.push_back(iMax);
}
return vans;
}
};
查看3道真题和解析