Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int[][] removeRowAndCol(int[][] matrix, int row, int col) {
- int[][] finalMatrix = new int[matrix.length-1][];
- for(int i = 0; i < matrix.length; i++){
- int c = 0;
- int r = 0;
- for(int j = 0; j < matrix[i].length; j++){
- if(i > row)
- r = 1;
- if (j > col)
- c = 1;
- if (i != row)
- finalMatrix[i - r] = new int[matrix[i].length < col ? matrix[i].length : matrix[i].length - 1];
- if(i != row && j != col) {
- finalMatrix[i-r][j-c] = matrix[i][j];
- }
- }
- }
- return finalMatrix;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement