Class Solution

java.lang.Object
g0001_0100.s0052_n_queens_ii.Solution

public class Solution extends Object
52 - N-Queens II.<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>the number of distinct solutions to the <strong>n-queens puzzle</strong></em>.</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> 2</p> <p><strong>Explanation:</strong> There are two distinct solutions to the 4-queens puzzle as shown.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 1</p> <p><strong>Output:</strong> 1</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 9</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • totalNQueens

      public int totalNQueens(int n)