滑动窗口的最大值 - 困难

*************

C++

topic: 239. 滑动窗口最大值 - 力扣(LeetCode)

*************

Give the topic an inspection.

Long time no see. Have too much series too see recently. I have to watch football matches around 苏超. I tryed really hard with no tickets. 大麦倒闭吧, rubbish. And I addicked in <better call saul>, Gus is fucking sexy. He is so professional and relariable. I like him so much and one day, I coubld be him, I could be sherlock, I could be Kumei Ennosuke, and they could be one of me.

And the first look I give it a glance, I notice the newest design cocept of Apple Inc.,which is liqued glass. And now I am listening a song called 璀璨冒险人, a good one for my recent days.

and back to the topic, I need a variable to store the maximum values and a current maximum to store the maxer on in the array. initialize an empty array and named result.

class Solution {
public:
    vector<int> maxSlidingWindow(vector<int>& nums, int k) {

        vector<int>  result; // 初始化一个空的容器
        int n = nums.size(); // 总是要这一步的

        for (int i = 0; i <= n - k; i++)
        {
            int current_max = nums[i]; // 先假设当前值是最大值,方便后续比较,这一步相当于初始化
            for (int j = i + 1; j < i + k; j++)
            {
                current_max = max(current_max, nums[j]); // 这是找出三个钟的最大值
            }

            result.push_back(current_max); // 之前学的在vector末尾压入
        }

        return result;
    }
};

And times out. 

Let's try new. Let's very welcome double-ended queue.

I write the above things about two weeks ago. And I am learning PID control recently. Today I have few works to do and the hot days makes me lazy. OK, not the hot days, I am lazy. Even if I am boring and have nothing to do, I donot want to write codes. But just write some code without any emotion. A thought comes to me, which is why I donot understand this when I was young. I was fickal and unpatience.

I donot understand deque. I will back next time.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值