数据量巨大的测试用例的该如何调试????

朔北冥 学生  2017-04-10 04:32:19
OJ上刷题碰到各测试用例没过,这个测试用例数据十分庞大。
想请教大家怎么对于大数据量的测试用例进行调试???


题目:
Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.

For example, given the following matrix:

1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

Return 6.

代码:

public class Solution {
public int maximalRectangle(char[][] matrix) {
if(matrix==null||matrix.length==0) return 0;
short[][] smatrix=new short[matrix.length+1][];
smatrix[matrix.length]=new short[matrix[0].length];
for(int i=0;i<matrix.length;i++){
smatrix[i]=new short[matrix[i].length];
for(int j=0;j<matrix[i].length;j++)
smatrix[i][j]=(short) (matrix[i][j]-'0');
}
for(int j=0;j<matrix[0].length;j++)
smatrix[matrix.length][j]=0;

//travel ever row
int max=-1;
for(int i=0;i<smatrix.length;i++){
count(smatrix[i]);
for(int j=0;j<smatrix[i].length;j++)
max=smatrix[i][j]>max?smatrix[i][j]:max;
}
if(smatrix.length==1) return max;


//travel every row and each row to the tail-1
for(int i=0;i<smatrix.length-1;i++){
andTwoRows(smatrix[i],smatrix[i+1]);
for(int j=i+1;j<smatrix.length;j++){
max=andTwoRows(max,j-i,smatrix[i],smatrix[j]);
if(!haveOne(smatrix[i])) break;
}
}
return max;
}
private void andTwoRows(short[] head,short[] cur){
short[] onehead=new short[head.length];
short[] onecur=new short[cur.length];
for(int i=0;i<head.length;i++){
if(head[i]>0)
for(int j=0;j<head[i];j++) onehead[i+j]=1;
if(cur[i]>0)
for(int j=0;j<cur[i];j++) onecur[i+j]=1;
}
for(int i=0;i<head.length;i++)
head[i]=(short) (onehead[i]&onecur[i]);
count(head);
}

private void count(short[] rows){
for(int i=0,k=-1;i<rows.length;i++){
if(rows[i]==0) k=-1;
if(k<0&&rows[i]==1) {k=i;continue;}
if(k>=0) {rows[k]+=rows[i];rows[i]=0;}
}
}
private int andTwoRows(int max,int h,short[] head,short[] cur){
short[] res=new short[head.length];
System.arraycopy(head,0,res,0,head.length);
andTwoRows(res,cur);

for(int i=0;i<head.length;i++){
if(res[i]<head[i]){
max=h*head[i]>max?h*head[i]:max;
head[i]=res[i];
}
}
return max;
}
private boolean haveOne(short[] row){
for(short tmp:row)
if(tmp>0) return true;
return false;
}
}

1

测试用例
"1111111111111101001111111100111011111111",
"1111011011111111101101111101111111111111",
"0111101011111101101101101111111111111111",
"0101101011111111111101111111010110111111",
"1111111111110111110110010111111111111111",
"1111111110110101111111111101011111101111",
"0110110101110011111111111111110111110101",
"0111111111111100111111100110011011010101",
"1111011110111111111011011011110101101011",
"1111111110111111111101101101110111101111",
"1110110011111111111100111111111111111111",
"1011111110111101111001110111111111111111",
"0110111111111111101111110111011111011111",
"1111111111111111011111111111110111111011",
"1111100111111110101100111111111111101111",
"1111101111111110111111011111111111011111",
"1111101111111111111111011001111110011111",
"1111110111111111011111111111110111110111",
"1011111111111111010111110010111110111111",
"1111110011111111111110111111111111111011",
"1111111111111111110111011111011111011011",
"1100011011111111111111011111011111111111",
"1111101011111111111101100101110011111111",
"1110010111111111111011011110111101111101",
"1111111111111101101111111111101111111111",
"1111111011111101111011111111111110111111",
"1110011111111110111011111111110111110111",
"1111111111111100111111010111111111110111",
"1111111111111111111111000111111111011101",
"1111110111111111111111111101100111011011",
"1111011011111101101101111110111111101111",
"1111111111011111111111111111111111111111",
"1111111111111111111111111111111111111111",
"1100011111111110111111111111101111111011",
"1111101111111101111010111111111111111111",
"0111111111110011111111110101011011111111",
"1011011111101111111111101111111111110011",
"1010111111111111111111111111111110011111",
"0111101111011111111111111111110111111111",
"0111111011111111011101111011101111111111",
"0111111111110101111011111101011001111011",
"1111111111111011110111111101111111101110",
"1111101111111100111111111110111111001111",
"1101101111110101111101111111100111010100",
"0110111111100111110010111110111011011101"
...全文
116 点赞 收藏 1
写回复
1 条回复
朔北冥 2017年04月12日
顶贴、、、、、
回复 点赞
发动态
发帖子
Java SE
创建于2007-09-28

3.4w+

社区成员

30.7w+

社区内容

Java 2 Standard Edition
社区公告
暂无公告