Simple solution in Java 28ms


  • 0
    T
    public class Solution {
        public boolean isValidSudoku(char[][] board) {
            int a=0,b=0;
            for(int i =0;i<9;i++){
                for(int j=0;j<9;j++){
                    if(board[i][j]=='.'){
                        continue;
                    }else{
                        for(int m=0;m<9;m++){
                            if(board[i][m]==board[i][j]&&m!=j){
                                return false;
                            }
                             if(board[m][j]==board[i][j]&&m!=i){
                                return false;
                            }
                            a=(i/3)*3+m/3;
                            b=(j/3)*3+m%3;
                            if(board[a][b]==board[i][j]&&a!=i&&b!=j){
                                return false;
                            }
                        }
                    }
                }
            }
            return true;
        }
    }
    

Log in to reply
 

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