You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
class Solution{
public:
vector<vector> sumZeroMatrix(vector<vector> a){
//Code Here
int n=a.size(),m=a[0].size();
int area=0,x1=-1,x2=-1,y1=-1,y2=-1;
for(int l=0;l<m;l++){
vectorarr(n);
for(int r=l;r<m;r++){
for(int i=0;i<n;i++){
arr[i]+=a[i][r];
}
unordered_map<int,int>mp;mp[0]=-1;
int sum=0,len=0,s=-1,e=-1;
for(int i=0;i<n;i++){
sum+=arr[i];
if(mp.find(sum)!=mp.end()){
if(len<i-mp[sum]){
len=i-mp[sum];
e=i;
s=mp[sum]+1;
}
}
else mp[sum]=i;
}
if(area<len*(r-l+1)){
area=len*(r-l+1);
y1=l;y2=r;
x1=s;x2=e;
}
}
}
vector<vector> ans;
if(x1==-1||x2==-1||y1==-1||y2==-1) return ans;
for(int i=x1;i<=x2;i++){
vectortemp;
for(int j=y1;j<=y2;j++){
temp.push_back(a[i][j]);
}
ans.push_back(temp);
}
return ans;
}
};
@getlost01
Beta Was this translation helpful? Give feedback.
All reactions