hash滑窗|dp

lcr107

多源bfs

注意init ret -1防重复入队

++if(x>=0 && x<m && y>=0 && y<n && retxy == -1)
// 最近距离 = 相邻0的距离 + 1
retxy = retab + 1;
++

class Solution {

typedef pair<int,int> pii;

int dx4={0,0,1,-1};

int dy4={1,-1,0,0};

public:

vector<vector<int>> updateMatrix(vector<vector<int>>& mat)

{

queue<pii> q;

int m=mat.size(),n=mat0.size();

vector<vector<int>> ret(m,vector<int>(n,0));

for(int i=0;i<m;i++)

{

for(int j=0;j<n;j++)

{

if(matij==0)

{

q.push({i,j});

}

else

{

// 标记未处理的1为-1

retij = -1;

}

}

}

while(!q.empty())

{

auto a,b = q.front();

q.pop();

for(int k=0;k<4;k++)

{

int x=a+dxk,y=b+dyk;

++if(x>=0 && x<m && y>=0 && y<n && retxy == -1)
{
// 最近距离 = 相邻0的距离 + 1
retxy = retab + 1;
++

q.push({x,y});

}

}

}

return ret;

}

};

lcr17

滑动窗口+两个哈希表

在s里找包含t所有字符的最短子串,找不到就返回空

class Solution {

public:

string minWindow(string s, string t) {

unordered_map<char, int> tag;

unordered_map<char, int> hash;

for (char c : t) {

tagc++;

}

int cnt = 0;

int tcnt = t.size();

int l = 0, r = 0;

int minLen = INT_MAX;

int start = 0;

int n = s.size();

while (r < n) {

char c = sr;

hashc++;

if (hashc <= tagc) {

cnt++;

}

r++;

while (cnt == tcnt)

{

++if (r - l < minLen) {++

++minLen = r - l;++

++start = l;++

}

char leftChar = sl;

++hashleftChar--;++

++if (hashleftChar < tagleftChar)++

++cnt--;++

l++;

}

}

return minLen == INT_MAX ? "" : s.substr(start, minLen);

}

};

lc1186

class Solution {

public:

int maximumSum(vector<int>& arr) {

int n=arr.size();

bool flag=false;

int maxNum=INT_MIN;

for(int i=0;i<n;i++){

if(arri>0){

flag=true;

break;

}

maxNum=max(maxNum,arri);

}

if(flag==false)return maxNum;

vector<int>pre(n+2),nex(n+2);

int add=0;

for(int i=1;i<=n;i++){

add+=arri-1;

++if(add<arri-1) add=arri-1;++

++prei=add>0?add:0;++

}

add=0;

for(int i=n;i>=1;i--){

add+=arri-1;

if(add<arri-1)add=arri-1;

nexi=add>0?add:0;

}

int ans=INT_MIN;

for(int i=1;i<=n;i++){

++ans=max(max(ans,prei-1+nexi+1+arri-1),prei-1+nexi+1);++

}

return ans;

}

};

相关推荐
爱刷碗的苏泓舒3 小时前
PPP-AR 中的参考星选取:数学原理、评价指标与切换处理
算法·gnss·模糊度固定·ppp-ar·星间单差·参考星·卫星端偏差
烬羽6 小时前
递归老写崩?一个"退回"公式,把回溯题变成填空题
javascript·深度学习·算法
闪电悠米6 小时前
力扣hot100-41.缺失的第一个正数-原地哈希详解
数据结构·算法·哈希算法
星空露珠7 小时前
28种颜色对应名称,
开发语言·数据库·算法·游戏·lua
QXWZ_IA8 小时前
桥梁数字孪生怎么落地?
人工智能·科技·算法·智能硬件·政务
Kel8 小时前
输出层与反分词(Output Layer & Detokenization)
人工智能·算法·架构
陕西企来客9 小时前
2026年7月技术好GEO优化方案:算法适配与内容策略
人工智能·算法·机器学习·技术好geo优化
风栖柳白杨9 小时前
【面试】AI算法工程师_空白自测版本
人工智能·算法·面试
闪电悠米10 小时前
力扣hot100-73.矩阵置零-标记数组详解
算法·leetcode·矩阵
栋***t10 小时前
从“纸质试卷”到“AI智能组卷”,麦塔在线考试系统如何重构出题逻辑?
java·大数据·人工智能·算法·重构