0%

Javascript(leetcode#51) First Missing Positive

Difficult:Hard

題目

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.

Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order.

Each solution contains a distinct board configuration of the n-queens’ placement, where ‘Q’ and ‘.’ both indicate a queen and an empty space, respectively.

翻譯

n-皇后謎題是在 n x n 棋盤上放置 n 個皇后以使沒有兩個皇后相互攻擊的問題。

給定一個整數 n,返回 n-queens 謎題的所有不同解。您可以按任何順序返回答案。

每個解決方案都包含一個獨特的 n-queens 佈局的電路板配置,其中“Q”和“.”。兩者分別表示一個皇后和一個空白空間。

範例

Example 1:
example

1
2
3
Input: n = 4
Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
Explanation: There exist two distinct solutions to the 4-queens puzzle as shown above

Example 2:

1
2
Input: n = 1
Output: [["Q"]]

解題思路

Solution

Code 1 :

1
2