n-queens-ii

Follow up for N-Queens problem.

Now, instead outputting board configurations, return the total number of distinct solutions.

n-queens-ii_第1张图片

可参考上一篇博客,这里只需要产生一个 可行解,就将计数器count++

import java.util.*;
public class Solution {
    private int count=0;
    public int totalNQueens(int n) {
        int[] cols=new int[n];
        for(int i=0;i


你可能感兴趣的:(算法设计)