Share My Code May Help U


  • 0
    public class Solution {
        public boolean isValidSudoku(char[][] board) {
            for (int i = 0; i < 9; ++i) {			
    			int num;			
    			boolean col[] = new boolean[10];
    			boolean row[] = new boolean[10];
    			boolean son[] = new boolean[10];
    			for (int j = 0; j < 9; ++j) {
    				num = board[3 * (i % 3) + j / 3][3 * (i / 3) + j % 3] - '0';
    				if (num > 0 && num < 10)
    					if (!son[num])
    						son[num] = true;
    					else
    						return false;
    				num = board[j][i] - '0';
    				if (num > 0 && num < 10)
    					if (!col[num])
    						col[num] = true;
    					else
    						return false;
    				num = board[i][j] - '0';
    				if (num > 0 && num < 10)
    					if (!row[num])
    						row[num] = true;
    					else
    						return false;					
    			}
    		}
    		return true;
        }
    }

Log in to reply
 

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