Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DATE: 03-01-2022
- // LINK: https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/submissions/870329177/
- class Solution {
- public int oddCells(int m, int n, int[][] indices) {
- int[][] finalMat = new int[m][n];
- for( int[] arr: finalMat){
- Arrays.fill(arr,0);
- }
- for(int[] index: indices){
- finalMat = incrementRow(finalMat, index[0],n);
- finalMat = incrementCol(finalMat, index[1],m);
- }
- int count=0;
- for(int[] row: finalMat){
- for(int col: row){
- if(col%2!=0) count++;
- }
- }
- return count;
- }
- public int[][] incrementRow(int[][] arr, int row, int n){
- for(int j=0;j<n;j++){
- arr[row][j]+=1;
- }
- return arr;
- }
- public int[][] incrementCol(int[][] arr, int col, int m){
- for(int i=0;i<m;i++){
- arr[i][col]+=1;
- }
- return arr;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement