1 line Python solution


  • 2
        def solveNQueens(self, n):
            return [['.' * v + 'Q' + '.' * (n - v - 1) for v in c] for c in itertools.permutations(range(n))
                    if (len(set(i + v for i, v in enumerate(c))) == n) and
                    (len(set(i - v for i, v in enumerate(c))) == n)]

  • 0

    This is brilliant


Log in to reply
 

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