java solution beat 98.29%


  • 0
    J

    public class Solution {

    public boolean isValidSudoku(char[][] board) {
        int[][] table1 = new int[9][9];
        int[][] table2 = new int[9][9];
        int[][][] table3 = new int[3][3][9];
        for(int i=0; i<=8; i++){
             for(int j=0; j<=8; j++){
                 if(board[i][j] == '.') continue;
                 else{
                     int num = board[i][j] - '0';
                     if(++table1[i][num-1] > 1) return false;
                     if(++table2[j][num-1] > 1) return false;
                     if(++table3[i/3][j/3][num-1]>1) return false;
                 }
            }
        }
    
    return true;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.