52_N-Queens II

The n-queens puzzle is the problem of placing n _queens on an _n×_n _chessboard such that no two queens attack each other.

Given an integer n, return the number of distinct solutions to the n-queens puzzle.

Example:

Solution: Backtracking

Idea:

  • The idea is the same as in 51_N-Queens.

  • The only difference is return the number of solution instead of all the solutions.

  • Make sure output is a global variable to be updated in the helper function.

Last updated

Was this helpful?