Lintcode34 N-Queens II solution problem solution
[topic description]
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.
According to the n-queen problem, now return the number of different solutions for n-queens instead of the specific placement layout.
[topic link]
Http://www.lintcode.com/en/problem/n-queens-ii/
[topic Analysis]
This problem is exactly the same as the solution of NQueens (refer to N QueensN Queens leetcode java for specific solution), except that the return value required is different. So it would be nice to change the result to be recorded slightly.
Because it involves recursion, result passes in reference types (List, arrays, etc.) so that it can be saved in layers of recursion, so an array of length 1 is used here to help count.
Of course, you can also use a global variable to help with counting.
[reference answer]
Http://www.jiuzhang.com/solutions/n-queens-ii/