Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. public static int[][] removeRowAndCol(int[][] matrix, int row, int col) {
  2. int[][] finalMatrix = new int[matrix.length-1][];
  3. for(int i = 0; i < matrix.length; i++){
  4. int c = 0;
  5. int r = 0;
  6. for(int j = 0; j < matrix[i].length; j++){
  7. if(i > row)
  8. r = 1;
  9. if (j > col)
  10. c = 1;
  11.  
  12. if (i != row)
  13. finalMatrix[i - r] = new int[matrix[i].length < col ? matrix[i].length : matrix[i].length - 1];
  14. if(i != row && j != col) {
  15. finalMatrix[i-r][j-c] = matrix[i][j];
  16. }
  17. }
  18. }
  19.  
  20. return finalMatrix;
  21. }
  22.  
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement