def solve(self, board, i, j):
        """
        dfs
        :param board: a 9x9 2D array
        :return: Boolean
        """
        if j>=9:
            return self.solve(board, i+1, 0)
        if i==9:
            return True

        if board[i][j]==".":
            for num in range(1, 10):
                num_str = str(num)  # try number
                # To speed up, use condition short-curcit.
                # row, col, square
                if all([board[i][col]!=num_str for col in xrange(9)]) and \
                        all([board[row][j]!=num_str for row in xrange(9)]) and \
                        all([board[i/3*3+count/3][j/3*3+count%3]!=num_str for count in xrange(9)]):
                    board[i][j] = num_str
                    if not self.solve(board, i, j+1):
                        board[i][j] = "."  # restore, backtrack, save space
                    else:
                        return True
        else:
            return self.solve(board, i, j+1)

        return False
dataset/ETHPy150Open algorhythms/LeetCode/036 Sudoku Solver.py/Solution.solve/original