va
BAN USERstatic void printMatrix(int[][] matrix, int i, int j) {
int row = i-1;
int col = 0;
int runningRowCount = row;
int runningColCount = 0;
while(row >= 0 && col < j) {
System.out.print(" " + matrix[row][col]);
// this is the exit condition
if(row == 0 && col == j-1) {
return;
}
if(row == i-1) {
if (runningRowCount != 0) {
runningRowCount--;
runningColCount=0;
} else {
runningColCount++;
}
row = runningRowCount;
col = runningColCount;
System.out.println(" ");
} else {
row++;
if(col == j-1) {
runningRowCount=0;
row = runningRowCount;
runningColCount++;
col = runningColCount;
System.out.println(" ");
} else {
col++;
}
}
}
}
this solution is without sorting the numbers. Also would work if you pass in k for kSum
- va November 24, 2017