← 返回 snowflake 的题目列表N-Queens
类型:qbank
The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.
N-Queens Problem
Problem Requirements
The n-queens puzzle challenges you to place n queens on a chessboard of size n x n. You must arrange them so that no two queens can attack one another.
Given an integer n, your goal is to find all distinct solutions to the puzzle. You can return the list of answers in any order.
Each solution represents a unique board layout. Use 'Q' to indicate a queen and '.' to indicate an empty space.
Sample Inputs
Example 1:
Input: n = 4
Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
Explanation:
There are two different ways to solve the puzzle for a 4x4 board.
Example 2:
Input: n = 1
Output: [["Q"]]
Input Limits
1 <= n <= 9