# who can tell me why,really confused

• public class Solution {
public int maximalRectangle(char[][] matrix) {
if (matrix == null || matrix.length == 0) {
return 0;
}
int max=0;
int length=matrix[0].length;
int []height=new int[length];
for(int i=0;i<matrix.length;i++){
for(int j=0;j<length;j++){
if(matrix[i][j]==0) height[j]=0;
else height[j]=height[j]+1;

``````            // height[j]=matrix[i][j]==0?0:(height[j]+1);
}
max=Math.max(max,maxRec(height));
}
return max;
}
public int maxRec(int []height){
if(height==null||height.length==0)
return 0;
int max=0;
Stack<Integer> stack=new Stack<>();
for(int i=0;i<height.length;i++){
while(!stack.isEmpty()&&height[i]<=height[stack.peek()]){
int j=stack.pop();
int k=stack.isEmpty()?-1:stack.peek();
int curArea=(j-k+1)*height[j];
max=Math.max(curArea,max);
}
stack.push(i);
}
while(stack.isEmpty()){
int j=stack.pop();
int k=stack.isEmpty()?-1:stack.peek();
int curArea=(j-k+1)*height[j];
max=Math.max(curArea,max);
}
return max;
}
``````

}

I debug my code in IDEA, it runs correctlly.But in leetcode ,it failed;

it return all ones

• ``````public class Solution {
public int maximalRectangle(char[][] matrix) {
if (matrix == null || matrix.length == 0) {
return 0;
}
int max=0;
int length=matrix[0].length;
int []height=new int[length];
for(int i=0;i<matrix.length;i++){
for(int j=0;j<length;j++){
if(matrix[i][j]==0) height[j]=0;
else height[j]=height[j]+1;
// height[j]=matrix[i][j]==0?0:(height[j]+1);
}
max=Math.max(max,maxRec(height));
}
return max;
}
public int maxRec(int []height){
if(height==null||height.length==0)
return 0;
int max=0;
Stack<Integer> stack=new Stack<>();
for(int i=0;i<height.length;i++){
while(!stack.isEmpty()&&height[i]<=height[stack.peek()]){
int j=stack.pop();
int k=stack.isEmpty()?-1:stack.peek();
int curArea=(j-k+1)*height[j];
max=Math.max(curArea,max);
}
stack.push(i);
}
while(stack.isEmpty()){
int j=stack.pop();
int k=stack.isEmpty()?-1:stack.peek();
int curArea=(j-k+1)*height[j];
max=Math.max(curArea,max);
}
return max;
}
``````

}

I debug my code in IDEA, it runs correctlly.But in leetcode ,it failed;

it return all ones

• @simple008 The first thing you need to do before `posting` a question is `read the instructions` at the head of the page and format your problem properly.

Thank you!

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.