51.N-Queens
51. N Queens
题目地址
https://leetcode.com/problems/n-queens/
https://www.lintcode.com/problem/n-queens/description
题目描述
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other(Any two queens can't be in the same row, column, diagonal line).
Given an integer n, return all distinct solutions to the n-queens puzzle.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' each indicate a queen and an empty space respectively.代码
Approach 1: Recursion
Time: O(N!) Space: O(N)
Last updated
Was this helpful?