Class Solution

java.lang.Object
g0001_0100.s0051_n_queens.Solution

public class Solution extends Object
51 - N-Queens.<p>Hard</p> <p>The <strong>n-queens</strong> puzzle is the problem of placing <code>n</code> queens on an <code>n x n</code> chessboard such that no two queens attack each other.</p> <p>Given an integer <code>n</code>, return <em>all distinct solutions to the <strong>n-queens puzzle</strong></em>. You may return the answer in <strong>any order</strong>.</p> <p>Each solution contains a distinct board configuration of the n-queens&rsquo; placement, where <code>'Q'</code> and <code>'.'</code> both indicate a queen and an empty space, respectively.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/11/13/queens.jpg" alt="" /></p> <p><strong>Input:</strong> n = 4</p> <p><strong>Output:</strong> [[&ldquo;.Q..&rdquo;,&ldquo;&hellip;Q&rdquo;,&ldquo;Q&hellip;&rdquo;,&ldquo;..Q.&rdquo;],[&ldquo;..Q.&rdquo;,&ldquo;Q&hellip;&rdquo;,&ldquo;&hellip;Q&rdquo;,&ldquo;.Q..&rdquo;]]</p> <p><strong>Explanation:</strong> There exist two distinct solutions to the 4-queens puzzle as shown above</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 1</p> <p><strong>Output:</strong> <a href="&quot;Q&quot;">&quot;Q&quot;</a></p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 9</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details