2021/8/21

两个leetcode困难

[//]: # (支持粘贴图片啦🎉🎉🎉)
[//]: # (保存的笔记可以在小程序中查看)

```
class Solution {
public:
    int shortestSubarray(vector<int>& nums, int k) {
        int ans = 10001010;
        int sum = 0,P = 0;
        int pre[500010];pre[0] = nums[0];
        int dp[50010],top = 0;
        for(int i = 1;i < nums.size(); ++ i){
           pre[i] = pre[i - 1] + nums[i];
        }
        for(int i = 0; i < nums.size(); ++ i){
            if(pre[i] >= k){
                 ans = min(ans,i + 1);
            }
            if(P == top){
                dp[top ++] = i; continue;
            }
            while(P < top && pre[i] <= pre[dp[top - 1]]){
                -- top;
            }
            while(P < top && pre[i] - pre[dp[P]] >= k){
                ans = min(ans,i - dp[P]);
                ++ P;
            }
            dp[top ++] = i;
        }
        if( ans == 10001010) return -1;
        return ans;
    }
};

[//]: # (支持粘贴图片啦🎉🎉🎉)
[//]: # (保存的笔记可以在小程序中查看)

```
class Solution {
public:
int pre[220][220];
vector<int> getMaxMatrix(vector<vector<int>>& matrix) {
int maxx = -101000000;
int x1,y1,x2,y2;
for(int i = 0; i < matrix.size();++ i){
for(int j = 0; j < matrix[0].size(); j ++){
if(i == 0) pre[i][j] = matrix[i][j];
else pre[i][j] = pre[i - 1][j] + matrix[i][j];
if(matrix[i][j] > maxx){
maxx = matrix[i][j]; x1 = x2 = i; y1 = y2 = j;
}
}
}

for(int i = 0; i < matrix.size(); i ++){
for(int j = i; j < matrix.size(); j ++){
int ans = 0;
int P = 0;
for(int k = 0; k < matrix[i].size(); ++ k){

if(i == 0){
if(ans + pre[j][k] > 0){
ans += pre[j][k];
if(ans > maxx){
x1 = i; x2 = j; y2 = k;y1 = P;
maxx = ans;
}
continue;
} else {

ans = 0;
P = k + 1;

}
continue;
}
int mul = pre[j][k] - pre[i - 1][k];
if(ans + mul > 0){
ans += mul;
if(ans > maxx){
x1 = i; x2 = j; y2 = k;y1 = P;
maxx = ans;
}
continue;
} else {
ans = 0;
P = k + 1;

}

}
}
}
vector<int> T;
T.push_back(x1);T.push_back(y1);
T.push_back(x2);T.push_back(y2);
return T;
}
};
```

```

  

一场笔试

一场面试

mysql45讲又看了五讲;同时学着如何设计了一个表。

复习整理了一些其他的问题

看了图解网络

 

posted @ 2021-08-21 22:18  风生  阅读(33)  评论(0编辑  收藏  举报